数据库插入数据"/>
ThinkPHP5 数据库插入数据
<?phpnamespace app\index\controller;use think\Controller;
use think\Db;class Index extends Controller
{public function index(){$db = Db::name('user');# insert 返回值是影响记录的行数 插入数// $res = $db->insert([// 'email' => 'imooc_1@qq',// 'password' => md5('imooc_1'),// 'username' => 'imooc_1'// ]);#insertGetId 返回值插入数据的自增id// $res = $db->insertGetId([// 'email' => 'imooc_1@qq',// 'password' => md5('imooc_1'),// 'username' => 'imooc_1'// ]);#insertAll 返回插入数据成功的行数$data = [];for($i=10; $i<20; $i++){$data[] = ['email' => "imooc_{$i}@qq",'password' => md5("imooc_{$i}"),'username' => "imooc_{$i}"];}$res = $db->insertAll($data);dump($res);}
}?>
更多推荐
ThinkPHP5 数据库插入数据
发布评论