Jump to content

how to connect to database?!?

vahid abdi

Recommended Posts

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

By the looks you just have to include config file and then you are free to use all PS codebase.





$query = new DbQuery();


$result = Db::getInstance(_PS_USE_SQL_SLAVE_)->executeS($query);

  • Like 2
Link to comment
Share on other sites

in the code above



it works pretty good

but now i want to do it like this


->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

You can check DbQueryCore class for all available options.



I can do one more for you:

$query2 = new DbQuery();

    ->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

// Is same as this
$query2->select('c.firstname, a.lastname');

// Add alias
$query2->select('c.firstname F, a.lastname L');
  • Like 3
Link to comment
Share on other sites

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 account

Sign in

Already have an account? Sign in here.

Sign In Now
  • Create New...