SQL语法错误。检查SQL语句。
你的PHP应用在使用PDO连接MySQL时遇到了SQL语法错误:
'pdo_code' => '42000',
'db_code' => 1064,
'db_error' => '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 = "John's Account";
$badSql = "SELECT * FROM users WHERE username = '" . $username . "'";
$goodSql = "SELECT * FROM users WHERE username = ?";
$stmt = $pdo->prepare($goodSql);
$stmt->execute([$username]);
$results = $stmt->fetchAll();
$namedSql = "SELECT * FROM users WHERE username = :username AND status = :status";
$namedStmt = $pdo->prepare($namedSql);
$namedStmt->execute([
':username' => $username,
':status' => 'active'
]);
$results = $namedStmt->fetchAll();