So I just wanted to insert a new record to database using by below query:
INSERT INTO ratings VALUES(\'\','".$userid."','".$rating."','".$itemid."')
I also tried it with parameters but that didn't work either.
This is the query printed to console:
INSERT INTO ratings VALUES('','13','3.5','5228')"
The Php Code is this:
$query = "INSERT INTO ratings VALUES(\'\','".$userid."','".$rating."','".$itemid."')";
echo '<script>console.log("'.$query.'");</script>';
DB::query($query);
And the function to execute the query:
public static function query($query, $params = array()) {
$statement = self::connect()->prepare($query);
$statement->execute($params);
if (explode(' ', $query)[0] == 'SELECT') {
$data = $statement->fetchAll();
return $data;
}
}
And the Error that i get is following:
Uncaught 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 '\'\','13','4','5228')'
at line 1 in D:\xampp\htdocs\updatedcollector\classes\DB.php:12