Reputation: 9
$stmt =$dbh->prepare('SELECT * FROM config WHERE group=:group AND name=:name');
$stmt->bindParam(':group',$group, PDO::PARAM_STR);
$stmt->bindParam(':name',$name, PDO::PARAM_STR);
Gives exception:
PDOException: SQLSTATE[42000]: Syntax error or access violation: 1064
You have an error in your SQL syntax; check the manual that corresponds to your MariaDB server
version for the right syntax to use near 'group=? AND name=?' at line 1
Tried to put the parameters in the execute function, same message.
PDO options i've set are:
PDO::ATTR_ERRMODE=> PDO::ERRMODE_EXCEPTION,
PDO::ATTR_DEFAULT_FETCH_MODE => PDO::FETCH_ASSOC,
PDO::ATTR_EMULATE_PREPARES => FALSE,
Upvotes: 1
Views: 40
Reputation: 1019
group
is a keyword in SQL. You may not used it as a column name without quoting it. In MySQL, things like column names are quoted with back-ticks, i.e. :
$stmt =$dbh->prepare('SELECT * FROM config WHERE `group` = :group AND `name` = :name');
Upvotes: 1
Reputation: 218798
group
is a reserved word and can't be used as an identifier without back-ticks in MariaDB:
SELECT * FROM `config` WHERE `group`= :group AND `name` = :name
Upvotes: 1