批改状态:合格
老师批语:
使用composer进行安装composer create-project topthink/think tp
找到config目录下的database.php文件进行配置








//1.1 增 insert 返回添加成功的条数// $data = [// 'name' => '小编',// 'email' => 'xiaobian@qq.com',// 'password' => sha1(123456),// 'reg_time' => time()// ];// $res = Db::table('user')->insert($data);// print_r($res);//1.2增 insertAll 返回添加成功的条数// $data = [// [// 'name' => '小编1',// 'email' => 'xiaobian0@qq.com',// 'password' => sha1(123456),// 'reg_time' => time()// ],// [// 'name' => '小编2',// 'email' => 'xiaobian2@qq.com',// 'password' => sha1(123456),// 'reg_time' => time()// ],// [// 'name' => '小编3',// 'email' => 'xiaobian3@qq.com',// 'password' => sha1(123456),// 'reg_time' => time()// ]// ];// $res = Db::table('user')->insertAll($data);// print_r($res);// 1.3 insertGetId 返回主键值// $data = [// 'name' => '小编4',// 'email' => 'xiaobian4@qq.com',// 'password' => sha1(123456),// 'reg_time' => time()// ];// $res = Db::table('user')->insertGetId($data);// print_r($res);//2.1 删除 delete 返回删除数据的条数 没删除则返回0// $res = Db::table('user')->where('id', '11')->delete();// echo '删除了' . $res . '条数据';//2.2 软删除 useSoftDelete 将某一个字段的值进行更改// $res = Db::table('user')->where('id', 10)->useSoftDelete('password', 2)->delete();// echo '删除了' . $res . '条数据';// 3.1 修改update 返回受到影响的条数 没有返回0// $data = [// 'password' => sha1(123456789),// ];// $res = Db::table('user')->where('id', 1)->update($data);// echo '修改了' . $res . '条数据';// 查询 select// $res = Db::table('user')->select();// printf("<pre>%s</pre>", print_r($res, true));
Copyright 2014-2025 https://www.php.cn/ All Rights Reserved | php.cn | 湘ICP备2023035733号