Jump to content

Converting code to use Prestashop classes?


Recommended Posts

I’m writing a new class for Prestashop.

I have some simple db access code in my current that looks like this:

Class Database {

 function query($query){
   $result = mysql_query($query);
     echo mysql_error();
   return $result;


And using it in my code:

$db = new Database;
$result = $db->query($sql);
if($result) {
 while($row = mysql_fetch_row($result))
   // iterate and do something with row data

How would I convert this to Prestashop “speak” using the Db class?
There is not going to be a template used here, only class code. This class
is to generate PDF files from database data so I do not need any presentation.
I already have everything, I just wanted to use PS classes to do it all.

Share this post

Link to post
Share on other sites

Execute returns the resulting object from the query and ExecuteS returns an array of all the rows from the query. Use Execute for INSERT, UPDATE and DELETE queries and ExecuteS for SELECT queries.

Share this post

Link to post
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...

Important Information

Cookies ensure the smooth running of our services. Using these, you accept the use of cookies. Learn More