0

I have a database named prestashop, a table ps_product and a field mq which is tinyInt.

If I do this query on console, it runs correctly, editing the value of a field in a record:

USE prestashop UPDATE ps_product SET mq = 0 WHERE id_product = 1

If I do this query programmatically (php):

mysql_query("USE prestashop 
                        UPDATE ps_product 
                        SET mq = 0 
                        WHERE id_product = 1;")
            or die("Query non valida: " . mysql_error());

and this is the error:

Query non valida: 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 'UPDATE ps_product SET mq = 0 WHERE id_product = 1' at line 2

why? In the console all proceeds correctly, and it really edit the value on the table

Al Lelopath
  • 6,448
  • 13
  • 82
  • 139
AlbertoZ
  • 154
  • 8
  • 2
    checkout mysql_select_db and mysql_connect and since you are new jump to PDO – Abhik Chakraborty Oct 22 '14 at 14:32
  • 1
    `USE` and `SELECT` are 2 queries. You should atleast have a delimeter between them. You don't USE database like that in `mysql_query`. Also `mysql_query` supports only one query. Note:mysql extension is [deprecated](http://stackoverflow.com/questions/13944956) as of PHP 5.5.0, and will be removed in the future. Instead, the [MySQLi](http://www.php.net/manual/en/book.mysqli.php) or [PDO_MySQL](http://www.php.net/manual/en/ref.pdo-mysql.php) extension should be used. Please don't use `mysql_*` to develop new code. – bansi Oct 22 '14 at 14:36
  • Read above comments, mysql is deprecated. Use mysqli instead. Be aware if you use semicolon, must use it in all commands. – Leandro Bardelli Oct 22 '14 at 15:30

1 Answers1

0

For update product detail in prestashop you should write query like that:

$sql = 'UPDATE '._DB_PREFIX_.'product SET mq=0 WHERE id_product=1';
if (!Db::getInstance()->execute($sql))
    die('error!');

I hope it would help you.