當我使用此代碼,我得到這個錯誤: 'where子句'
1054未知列 'rules_id.rules':
MySQL的PDO多選
錯誤:SQLSTATE [42S22]:列未找到
我真的不知道該怎麼這樣
在我的數據庫創造的東西我有:
表:規則,用戶
列:
(規則)=> rules_id,allias_name,編輯,刪除
(用戶)=> users_id,用戶名,密碼,rules_id
*我想創建一個用戶訪問規則
<?php
$servername = "localhost";
$username = "root";
$password = "";
$dbname = "demo";
try {
$db = new PDO("mysql:host=$servername;dbname=$dbname", $username, $password);
$db->setAttribute(PDO::ATTR_ERRMODE, PDO::ERRMODE_EXCEPTION);
\t $sql = $db->query("SELECT * FROM users where rules_id.rules = rules_id.users");
\t while ($row = $sql->fetch(PDO::FETCH_ASSOC)){
\t \t echo $row["users_id"];
\t }
\t \t
\t \t
}
catch(PDOException $e) {
echo "Error: " . $e->getMessage();
}
$conn = null;
?>
你可能想加入的規則表到用戶表。正確的SQL語法是'tablename.columnname'。 'SELECT * FROM users JOIN rules t2 ON users.rules_id = rules.rules_id ' – nimmneun