Jump to content

prestashop module using mysqli_connect showing No database selected


Recommended Posts

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

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

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

×
×
  • Create New...