Mysql Safe Update

Mysql Safe Update

estudiosestudios Posts: 52Questions: 0Answers: 0
edited September 2013 in General
Allan

I got following error


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 '' at line 2' in /var/www/consultas/_/EE/php/lib/Database/Driver/Mysql/Query.php:98
Stack trace:
#0 /var/www/consultas/_/EE/php/lib/Database/Driver/Mysql/Query.php(98): PDOStatement->execute()
#1 /var/www/consultas/_/EE/php/lib/Database/Query.php(598): DataTables\Database\DriverMysqlQuery->_exec()
#2 /var/www/consultas/_/EE/php/lib/Database/Query.php(206): DataTables\Database\Query->_raw('DELETE FROM not...')
#3 /var/www/consultas/_/EE/php/lib/Database/Database.php(215): DataTables\Database\Query->exec('DELETE FROM not...')
#4 /var/www/consultas/_/EE/php/table.EEofertas.php(69): DataTables\Database->sql('DELETE FROM not...')
#5 {main}
thrown in /var/www/consultas/_/EE/php/lib/Database/Driver/Mysql/Query.php on line 98


The line is:
// Delete notas which are part of ofertas
$db->sql( "DELETE FROM notas WHERE id IN (
SELECT idnota FROM ofertas WHERE id IN ( ".implode(', ', $ids)." )"
);
I did type the sql in MySQLWorkbench and did not work until I disable the option "Safe Update". So I am sure that the code is OK but seems that I need to disable safe update from some place in Editor.

Any help?

Replies

  • allanallan Posts: 63,498Questions: 1Answers: 10,471 Site admin
    What is in $ids? My guess is that it is empty? Also echo out the generated SQL - it looks safe. Beyond that, you might need to look at how to allow a safe update via an SQL command which you'd execute before that.

    Allan
  • estudiosestudios Posts: 52Questions: 0Answers: 0
    Allan, you may remember. You did this
    // DELETING THE ROW IN NOTAS
    if ( isset( $_POST['action'] ) && $_POST['action'] === 'remove' ) {
    $ids = array();

    // Build array of ofertas ids
    for ( $i=0 ; $isql( "DELETE FROM notas WHERE id IN (
    SELECT idnota FROM ofertas WHERE id IN ( ".implode(', ', $ids)." )"
    );
    }

    I did echo the generated SQL paste in Workbench and Works ok (with safe mode disable).
    D0 you think that there is a syntax error in the generation of $ids????
  • estudiosestudios Posts: 52Questions: 0Answers: 0
    I've found it.

    There is a ) missing!!
This discussion has been closed.