このクエリは機能する必要がありますか?そうでない場合、PHP で PDO を使用してクエリを別のクエリに配置するにはどうすればよいですか?
これが私のクエリです:
$userid = array($users->school_name_from_id($_SESSION['user_id']), $_SESSION['user_id'], $_SESSION['user_id']);
$statementString =
'SELECT * FROM schoolinfo
WHERE schoolinfo.school = ? AND
SELECT count(*) FROM friendstable
WHERE friendstable.user_ID = ?
AND frienstable.friend_ID = schoolinfo.id <= 0
AND
SELECT count(*) FROM friendstable
WHERE friendstable.user_ID = schoolinfo.id
AND friendstable.friend_ID = ? <= 0
ORDER BY RAND()
LIMIT 6';
$stmt = $database->_link->prepare($statementString);
$stmt->execute($userid);
$array = $stmt->fetchAll(PDO::FETCH_ASSOC);
print_r($array);
実行時に表示される完全なエラーは次のとおりです。
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 'SELECT count(*) FROM friendstable WHERE friendstable.user_ID = '1' AND frienstab' at line 1' in C:\xampp\htdocs\thinkaztech\PHP\getSocialInformation.php:20 Stack trace: #0 C:\xampp\htdocs\thinkaztech\PHP\getSocialInformation.php(20): PDOStatement->execute(Array) #1 {main} thrown in C:\xampp\htdocs\thinkaztech\PHP\getSocialInformation.php on line 20