Skip to content

Instantly share code, notes, and snippets.

@des1roer des1roer/data.php
Created Jun 3, 2017

Embed
What would you like to do?
<?php
ini_set('error_reporting', E_ALL);
ini_set('display_errors', 1);
define('__ROOT__', dirname(dirname(dirname(__FILE__))));
require_once(__ROOT__.'/php/database.php');
//db properties
define('DB_TABLE', 'kinozal');
$dbn = DB_TABLE;
// make a connection to mysql here
$db = Database::get();
date_default_timezone_set('Asia/Yekaterinburg');
if (empty($_REQUEST['act'])) die('no action');
$act = $_REQUEST['act'];
switch ($act) {
case 'load':
$sql = "SELECT `COLUMN_NAME` as cn, DATA_TYPE as dt, COLUMN_COMMENT as c
FROM `INFORMATION_SCHEMA`.`COLUMNS`
WHERE `TABLE_SCHEMA`= DATABASE()
AND `TABLE_NAME`='{$dbn}' AND `COLUMN_NAME` not in ('id', 'dt_create', 'comment', 'is_active', 'user')";
echo json_encode($db->select($sql));
break;
case 'add':
try {
$data = $_POST['data'];
$data['user'] = $_POST['user'];
$id = $db->insert(DB_TABLE, $data);
echo json_encode(array($id));
} catch (PDOException $e) {
echo json_encode(array('error' => $e));
}
break;
case 'edit':
try {
$_POST['data']=array_map('trim',$_POST['data']);
$where = array(PKEY => $_POST['data']['id']);
$id = $db->update(DB_TABLE, $_POST['data'], $where);
echo json_encode(array($id));
} catch (PDOException $e) {
echo json_encode(array('error' => $e));
}
break;
case 'del':
try {
$where = array(PKEY => $_POST['data']['id']);
$id = $db->delete(DB_TABLE, $where);
echo json_encode(array($id));
} catch (PDOException $e) {
echo json_encode(array('error' => $e));
}
break;
default :
break;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.