PHP MySQLi Database Class
PHP MySQLi Database Class 是个一个 PHP 封装的 MySQL 类,使用 MySQLi 。
插入查询
$data = array( 'login' => 'admin', 'firstName' => 'John', 'lastName' => 'Doe',);$id = $db->insert('users', $data)if($id) echo 'user was created. Id='.$id;
选择查询
$users = $db->get('users'); //contains an array of all users $users = $db->get('users', 10); //contains an array 10 users
或者选择自定义列级
$stats = $db->getOne ("users", null, "sum(id), count(*) as cnt");echo "total ".$stats['cnt']. "users found";$cols = Array ("id, name, email");$users = $db->get ("users", null, $cols);foreach ($users as $user) { print_r ($user);}
或者只选择一行
$db->where ("id", 1);$user = $db->getOne ("users");echo $user['id'];
更新查询
$data = array ( 'firstName' => 'Bobby', 'lastName' => 'Tables');$db->where('id', 1);if($db->update('users', $data)) echo 'successfully updated';
删除查询
$db->where('id', 1);if($db->delete('posts')) echo 'successfully deleted';
评论