查询数据库中相关信息
作者QQ:67065435 QQ群:669756510
本站内容全部为作者原创,转载请注明出处!
示例代码 ```php <?php //ext:pdo //ext:pdo_mysql
注意:如果用'fetch'代替'fetchAll'则返回的是一维数组,且是第一条结果
最简单的方式执行
$dbh = new PDO('mysql:dbname=book_base;host=192.168.1.137', 'root', 'root'); $dbh->exec("set names utf8"); $sql = <<
fetchAll($sql); unset($dbh); 查询1条结果
$result = $dbh->fetch($sql); unset($dbh);
按序绑定参数执行
$dbh = new PDO('mysql:dbname=book_base;host=192.168.1.137', 'root', 'root');
$dbh->exec("set names utf8");
$sql = <<
查询1条结果
$res = $sth->fetch(); unset($sth); unset($dbh);
按key绑定参数执行
$dbh = new PDO('mysql:dbname=book_base;host=192.168.1.137', 'root', 'root');
$dbh->exec("set names utf8");
$sql = <<
查询1条结果
$res = $sth->fetch(); unset($sth); unset($dbh); ```