php pdo对象的 query方法 为什么不执行 没有返回数据
代码:$dsn="mysql:dbname=myblog;host=localhost";$user="root";$password="root";try{$dbh=n...
代码:
$dsn ="mysql:dbname=myblog;host=localhost";
$user="root";
$password="root";
try {
$dbh = new PDO($dsn, $user, $password);
} catch (PDOException $e) {
echo 'Connection failed: ' . $e->getMessage();
}
$sql = "SELECT * FROM posts";
$str = $dbh->query($sql);
var_dump($str);
echo '<br>';
var_dump(($dbh->errorInfo()));
输出:
object(PDOStatement)#2 (1) {
["queryString"]=>
string(19) "SELECT * FROM posts"
}
array(3) {
[0]=>
string(5) "00000"
[1]=>
NULL
[2]=>
NULL
}
ps:posts表内是有记录的。 展开
$dsn ="mysql:dbname=myblog;host=localhost";
$user="root";
$password="root";
try {
$dbh = new PDO($dsn, $user, $password);
} catch (PDOException $e) {
echo 'Connection failed: ' . $e->getMessage();
}
$sql = "SELECT * FROM posts";
$str = $dbh->query($sql);
var_dump($str);
echo '<br>';
var_dump(($dbh->errorInfo()));
输出:
object(PDOStatement)#2 (1) {
["queryString"]=>
string(19) "SELECT * FROM posts"
}
array(3) {
[0]=>
string(5) "00000"
[1]=>
NULL
[2]=>
NULL
}
ps:posts表内是有记录的。 展开
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询