/** * Drop column */ private function drop_column($keys) { $this->data = self::getJSON($this->file, true); if (!is_array($keys)) { $keys = self::trim_array(explode(',', $keys)); } $new_data = array(); if (self::check_array($keys, true)) { self::$error = array('code' => 104, 'message' => 'Somthing wrong width parameters: "' . implode(',', $keys) . '"'); return false; } if (!$this->check_table_keys($keys)) { self::$error = array('code' => 202, 'message' => 'Try to drop an unexisting column from table "' . $this->table . '"'); return false; } foreach ($keys as $key) { if ($number = array_search($key, $this->data['settings']['keys'])) { unset($this->data['settings']['keys'][$number]); } if ($this->data['settings']['auto_increment'] == $key) { $this->data['settings']['auto_increment'] = false; } if (isset($this->data['settings']['default_values'][$key])) { unset($this->data['settings']['default_values'][$key]); } } foreach ($this->data['rows'] as $row) { foreach ($keys as $key) { unset($row[$key]); } $new_data[] = $row; } $this->data['rows'] = $new_data; return self::setJSON($this->file, $this->data); }
$result = JDB::table('habr')->delete($where); if ($result) { echo '<p>Из таблицы удалены записи с id = ' . implode(',', $where['id']) . '</p>'; echo '<p>Количество записей в таблице: ' . count(JDB::table('habr')->select('*')) . '</p>'; } /* * Test 12 */ echo '#12'; if (JDB::table('habr')->truncate()) { echo '<p>Таблица очищена.</p>'; } /* * Test 13 */ echo '#13'; $keys = array('id' => array('auto_increment'), 'name', 'title', 'status' => array('default' => 'online')); if (JDB::create('habr_1', $keys)) { echo '<p>Создана таблица "habr_1";</p>'; } /* * Test 14 */ echo '#14'; $keys = array('id' => array('auto_increment'), 'name', 'title', 'status' => array('default' => 'online')); if (!JDB::create('habr_1', $keys)) { echo "<p>Status: " . JDB::status(true) . "\n"; echo "Status code: " . JDB::status() . "</p>"; } $end_time = microtime() - $start_time; echo '<p>' . $end_time . ' s.</p>';
define('PATH', dirname(__FILE__) . DS); define('LIBS', PATH . 'libs' . DS); function dd() { echo "<pre>"; call_user_func_array('var_dump', func_get_args()); echo "</pre>"; exit; } require LIBS . 'jsondb.php'; require LIBS . 'dispatch.php'; config('dispatch.url', '/git/JSONDB/test_3/api/'); JDB::configure(PATH . 'jdb' . DS); on('GET', '/', function () { $keys = array('id' => array('auto_increment'), 'name', 'login', 'date', 'guid', 'text'); $result = JDB::create('users', $keys); if (!$result) { var_dump(JDB::status(true)); } else { echo 'ok'; } $data = array('name' => 'Name', 'login' => 'Login', 'date' => 'Date', 'guid' => 'Guid', 'text' => 'Text'); dd(JDB::table('users')->insert($data)); }); on('POST', 'user', function () { $result = JDB::table('users')->insert(request_body()); if ($result) { echo "ok\n"; } }); dispatch();