Eptun
Eptun

Reputation: 13

Uncaught exception 'PDOException' with message 'SQLSTATE[42000]: Syntax error or access violation: 1064

I'm making a chat and I stumbled across an error. The error is:

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 'INSERT INTO guildchat(guildID, playerID, message, `time`, chattime) VALUES(?, ?,' at line 1' in C:\xampp\htdocs\sf\sexyutility.php:14 Stack trace:#0 C:\xampp\htdocs\sf\sexyutility.php(14): PDO->prepare('SELECT @cht := ...')#1 C:\xampp\htdocs\req.php(2659): chatInsert('tewtewt', 53, 35)#2 {main} thrown in C:\xampp\htdocs\sf\sexyutility.php on line 14

The code is:

function chatInsert($message, $guild, $player){
    $time = time();
    $chattime = $GLOBALS['db']->prepare("SELECT @cht := Max(chattime) AS chattimer FROM guildchat WHERE guildID = :guild; INSERT INTO guildchat(guildID, playerID, message, `time`, chattime) VALUES(:guild, :player, :msg, :timers, @cht + 1)");
    $chattime->bindParam(":guild", $guild);
    $chattime->bindParam(":player", $player);
    $chattime->bindParam(":msg", $message);
    $chattime->bindParam(":timers", $time);
    $chattime->execute();
    return $chattime->fetch(PDO::FETCH_ASSOC)['chattimer'] + 1;
}

Upvotes: 1

Views: 1059

Answers (1)

I wrestled a bear once.
I wrestled a bear once.

Reputation: 23379

you can only do one query at a time with PDO prepare. you're running two. you will have to do it in 2 separate statements.

I guess I was wrong. Instead of removing the answer, I'll leave this link here as a reference.

PDO Support for multiple queries

It's supported, but with a few caveats.

Upvotes: 0

Related Questions