看不见的 MYSQL 错误
Unseen MYSQL Error
我的 MySQL 语句收到以下错误 -
PHP Fatal error: Uncaught exception 'PDOException' with message 'SQLSTATE[42000]: Syntax error or access violation: 1064 You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near ':username' at line 1'
现在这是我的代码的一部分,包括语句 -
$dbh = pdo_users();
$stmt = $dbh->query("SELECT * FROM users WHERE username=:username");
$stmt->bindParam(':username', $username);
$stmt->execute();
$info = $stmt->fetchAll(PDO::FETCH_ASSOC);
这是我的连接 -
function pdo_users()
{
try
{
$connect = new PDO('mysql:host=localhost;dbname=mydb', 'username', 'password');
$connect->setAttribute(PDO::ATTR_ERRMODE, PDO::ERRMODE_EXCEPTION);
$connect->setAttribute(PDO::ATTR_PERSISTENT, true);
}
catch (PDOException $e)
{
header('Location: error.php');
}
return $connect;
}
我的 MySQL 语句收到以下错误 -
PHP Fatal error: Uncaught exception 'PDOException' with message 'SQLSTATE[42000]: Syntax error or access violation: 1064 You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near ':username' at line 1'
现在这是我的代码的一部分,包括语句 -
$dbh = pdo_users();
$stmt = $dbh->query("SELECT * FROM users WHERE username=:username");
$stmt->bindParam(':username', $username);
$stmt->execute();
$info = $stmt->fetchAll(PDO::FETCH_ASSOC);
这是我的连接 -
function pdo_users()
{
try
{
$connect = new PDO('mysql:host=localhost;dbname=mydb', 'username', 'password');
$connect->setAttribute(PDO::ATTR_ERRMODE, PDO::ERRMODE_EXCEPTION);
$connect->setAttribute(PDO::ATTR_PERSISTENT, true);
}
catch (PDOException $e)
{
header('Location: error.php');
}
return $connect;
}