MagicFire Posted February 27, 2013 Share Posted February 27, 2013 (edited) Hi, I have a problem. My PS 1.5.2 refuses to execute valid SQL statement. I don't know why. The code is: Db::getInstance()->execute('INSERT INTO `'._DB_PREFIX_.'slider` (`id_slider_image`,`name`, `position`) VALUES (NULL,"'.$name.'", '.$position.')'); which leads to result INSERT INTO `ps_slider` (`id_slider_image`,`name`, `position`) VALUES (NULL,"Filter_bg.png", 1) which is absolutely correct. If I take this result and copy it to the phpmyadmin SQL console, it works. So could anybody please tell me, where could be the problem? I found out, that even a pure php functions isn't working too. But selecting is ok. Could be some permission problem? It's my own plugin. But if I can do select sqls why not the insert ones? If I do this: $sql = "INSERT INTO `"._DB_PREFIX_."slider` (`id_slider_image`,`name`, `position`) VALUES (NULL,'".$name."', ".$position.")"; $result = mysql_query($con,$sql) or die("Bad query: " . mysql_error()); it exists with this: Bad query: Where could be problem? Thanks Edited February 27, 2013 by MagicFire (see edit history) Link to comment Share on other sites More sharing options...
coeos.pro Posted February 27, 2013 Share Posted February 27, 2013 Hi, http://www.prestashop.com/blog/en/best-practices-class-db-prestashop-1-5/ try this : Db::getInstance()->insert('slider', array('id_slider_image' => Null, 'name' => 'Filter_bg.png', 'position' => 1), true); Link to comment Share on other sites More sharing options...
MagicFire Posted February 27, 2013 Author Share Posted February 27, 2013 No, it won't work. It simply doesn't insert anything. And this problem is focusing only to my plugin. Others working well. So I guess there must be something with permission (or anything like that). Because it doesn't throw any error message, even with all debuging on. Strange is, that when I try to force him to do this function,it leaves the blank page (but no error, nothing, just blank page). I've never has any experience with behavior like this. Link to comment Share on other sites More sharing options...
coeos.pro Posted February 27, 2013 Share Posted February 27, 2013 'id_slider_image' => Null in the database , id_slider_image is "NOT NULL" ? Link to comment Share on other sites More sharing options...
MagicFire Posted February 27, 2013 Author Share Posted February 27, 2013 Yes, it's the autoincrement ID. So maybe this could be the problem? How can I insert empty value? So it will fill it with the autoincrement value? Link to comment Share on other sites More sharing options...
coeos.pro Posted February 27, 2013 Share Posted February 27, 2013 if it's auto increment you must not indicate it, try: Db::getInstance()->insert('slider', array('name' => 'Filter_bg.png', 'position' => 1), true); Link to comment Share on other sites More sharing options...
MagicFire Posted February 27, 2013 Author Share Posted February 27, 2013 OK, now it seems working. Thank you very much. Link to comment Share on other sites More sharing options...
Recommended Posts
Create an account or sign in to comment
You need to be a member in order to leave a comment
Create an account
Sign up for a new account in our community. It's easy!
Register a new accountSign in
Already have an account? Sign in here.
Sign In Now