php pdo对象的 query方法 为什么不执行
源码:$dsn="mysql:dbname=mydbname;host=localhost";$user="root";$password="root";try{$dbh...
源码:
$dsn ="mysql: dbname=mydbname; 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 LIMIT 0, 30 ";
$str = $dbh->query($sql);
var_dump($str);
print_r($str->errorInfo());//12行
输出:
bool(false)
Fatal error: Call to a member function errorInfo() on a non-object in D:\wwwroot\htdocs\test.php on line 12 展开
$dsn ="mysql: dbname=mydbname; 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 LIMIT 0, 30 ";
$str = $dbh->query($sql);
var_dump($str);
print_r($str->errorInfo());//12行
输出:
bool(false)
Fatal error: Call to a member function errorInfo() on a non-object in D:\wwwroot\htdocs\test.php on line 12 展开
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询