prestashop_newuser Posted October 16, 2013 Share Posted October 16, 2013 Hi, I am doing a small module in prestashop (1.5.5.0). Here in one position I need ajax to fetch some data from database. For that I have made my query like include '../../../config/settings.inc.php'; include '../../../config/defines.inc.php'; include '../../../config/config.inc.php'; mysql_connect(_DB_SERVER_,_DB_USER_,_DB_PASSWD_) or die(mysql_error()); mysql_select_db(_DB_NAME_) or die(mysql_error()); $result = mysql_query("SELECT DISTINCT `city_name` FROM "._DB_PREFIX_."storeinfo WHERE `state_name`='".$_GET['city']."'") or die(mysql_error()); here its working fine. But when the module was added to the prestashop addons they gave a response that "Hello, It's absolutly forbidden to use the PHP MySQL functions (mysql_connect, mysql_query... it's deprecated), you must use the Db class functions, like Db::getInstance()->Execute("your-request"); You must also use the Tools::getValue() static method to parse your server vars like $_GET, not the $_GET directly. But now as per the suggestion I am using mysqli_connect its not working. Here is my latest changes include '../../../config/settings.inc.php'; include '../../../config/defines.inc.php'; include '../../../config/config.inc.php'; $link = mysql_connect(_DB_SERVER_,_DB_USER_,_DB_PASSWD_,_DB_NAME_) or die("Error " . mysqli_error($link)); and it is showing as in output No database selected.. So can someone kindly tell me what is the issue here? Any help and suggestions will be really appreciable. Thanks Link to comment Share on other sites More sharing options...
Anton_bcn Posted October 16, 2013 Share Posted October 16, 2013 you have an answer by your salf dont use manual connection, use like Prestashop told you Or use this but not like a module. Just like separate script on you webserver like /myshop/myscript.php It cant be done because "Hello, It's absolutly forbidden to use the PHP MySQL functions (mysql_connect, mysql_query... it's deprecated), you must use the Db class functions, like Db::getInstance()->Execute("your-request"); You must also use the Tools::getValue() static method to parse your server vars like $_GET, not the $_GET directly. Link to comment Share on other sites More sharing options...
prestashop_newuser Posted October 16, 2013 Author Share Posted October 16, 2013 you have an answer by your salf dont use manual connection, use like Prestashop told you Or use this but not like a module. Just like separate script on you webserver like /myshop/myscript.php It cant be done because "Hello, It's absolutly forbidden to use the PHP MySQL functions (mysql_connect, mysql_query... it's deprecated), you must use the Db class functions, like Db::getInstance()->Execute("your-request"); You must also use the Tools::getValue() static method to parse your server vars like $_GET, not the $_GET directly. I am not getting you properly can you give me some example of code or any demo..I am just a newbie in prestashop so I want some suggestions and help... Link to comment Share on other sites More sharing options...
vekia Posted October 16, 2013 Share Posted October 16, 2013 I am not getting you properly can you give me some example of code or any demo..I am just a newbie in prestashop so I want some suggestions and help... you've got example in message from addons team... Db::getInstance()->Execute("your-request"); more info in documentation: http://doc.prestashop.com/display/PS15/DB+class+best+practices 1 Link to comment Share on other sites More sharing options...
prestashop_newuser Posted October 16, 2013 Author Share Posted October 16, 2013 you've got example in message from addons team... Db::getInstance()->Execute("your-request"); more info in documentation: http://doc.prestashop.com/display/PS15/DB+class+best+practices But why the mysqli_connect is not working here? Link to comment Share on other sites More sharing options...
vekia Posted October 16, 2013 Share Posted October 16, 2013 it should work. but it isn't good idea to use this method. you don't have to use mysqli_connect because connection is defined in Db class Link to comment Share on other sites More sharing options...
Recommended Posts