插入数据库中相关信息
作者QQ:67065435 QQ群:669756510
本站内容全部为作者原创,转载请注明出处!
示例代码
```php
<?php
//ext:pdo
//ext:pdo_mysql
最简单的方式执行(exec返回受影响行数)
$dbh = new PDO('mysql:dbname=book_base;host=192.168.1.137', 'root', 'root');
$dbh->exec("set names utf8");
$sql = <<exec($sql);
unset($dbh);
按序绑定参数执行(execute返回执行bool结果)
$dbh = new PDO('mysql:dbname=book_base;host=192.168.1.137', 'root', 'root');
$dbh->exec("set names utf8");
$sql = <<prepare($sql);
$sth->bindValue(1, 4);
$sth->bindValue(2, 'a126');
$sth->bindValue(3, '1234567890');
$sth->bindValue(4, '1234567890');
$sth->bindValue(5, '测试昵称4');
$sth->bindValue(6, 1506743300);
$sth->bindValue(7, 1506743300);
$sth->bindValue(8, 1506743300);
$res = $sth->execute();
unset($sth);
unset($dbh);
按key绑定参数执行(execute返回执行bool结果)
$dbh = new PDO('mysql:dbname=book_base;host=192.168.1.137', 'root', 'root');
$dbh->exec("set names utf8");
$sql = <<prepare($sql);
$sth->bindParam('id', $id);
$sth->bindParam('user_name', $user_name);
$sth->bindParam('user_skey', $user_skey);
$sth->bindParam('user_uuid', $user_uuid);
$sth->bindParam('user_nick', $user_nick);
$sth->bindParam('free_time', $free_time);
$sth->bindParam('login_time', $login_time);
$sth->bindParam('insert_time', $insert_time);
$res = $sth->execute();
unset($sth);
unset($dbh);
```