vahid abdi Posted June 7, 2015 Share Posted June 7, 2015 i want to connect to database in a file that i've created in main folder of prestashop... actually i want to use it's own classes to connect.. what would i add in my code? i need this soon.. so plz help if you can thanks for helping ... Link to comment Share on other sites More sharing options...
blackarma Posted June 7, 2015 Share Posted June 7, 2015 By the looks you just have to include config file and then you are free to use all PS codebase. Example: <?php require(dirname(__FILE__).'/config/config.inc.php'); $query = new DbQuery(); $query ->select('*') ->from('customer') ->limit(10); $result = Db::getInstance(_PS_USE_SQL_SLAVE_)->executeS($query); d($result); 2 Link to comment Share on other sites More sharing options...
vahid abdi Posted June 7, 2015 Author Share Posted June 7, 2015 thank u so much it worked pretty good Link to comment Share on other sites More sharing options...
vahid abdi Posted June 8, 2015 Author Share Posted June 8, 2015 in the code above $query->select('*')->from('customer')->limit(10); it works pretty good but now i want to do it like this $query->select('column1,column2')->from('customer, address') ->where('customer.column1="1" AND address.column2="something"'); ........ yea i want to take data from two tables that column1 belongs to customer and the other one to address but it doesn't works what can i do??? Link to comment Share on other sites More sharing options...
blackarma Posted June 8, 2015 Share Posted June 8, 2015 You can check DbQueryCore class for all available options. I can do one more for you: $query2 = new DbQuery(); $query2 ->select('c.firstname') ->select('a.lastname') ->from('customer', 'c') ->leftjoin('address', 'a', 'c.id_customer = a.id_customer') ->where('c.active = 1') ->where('a.phone = 0102030405'); $result2 = Db::getInstance(_PS_USE_SQL_SLAVE_)->executeS($query2); You can write it in many forms, just pick one you like For example: // This $query2->select('c.firstname'); $query2->select('a.lastname'); // Is same as this $query2->select('c.firstname, a.lastname'); // Add alias $query2->select('c.firstname F, a.lastname L'); 3 Link to comment Share on other sites More sharing options...
vahid abdi Posted June 9, 2015 Author Share Posted June 9, 2015 ohh thanks blackarma it helped me so much .. thank again 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