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;
query)选择查询
$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'];
query)更新查询
$data = array ( 'firstName' => 'Bobby', 'lastName' => 'Tables');$db->where('id', 1);if($db->update('users', $data)) echo 'successfully updated';
query)删除查询
$db->where('id', 1);if($db->delete('posts')) echo 'successfully deleted';