MrBaseball34 Posted August 23, 2010 Share Posted August 23, 2010 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); if($this->debug_mode) { echo mysql_error(); } return $result; } } And using it in my code: $db = new Database; $sql = 'SELECT * FROM TABLE' $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 classis 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. Link to comment Share on other sites More sharing options...
rocky Posted August 24, 2010 Share Posted August 24, 2010 Why aren't you using code like the following? $result = Db::getInstance()->ExecuteS('SELECT * FROM TABLE'); foreach ($result as $row) { // Do something with row data } Link to comment Share on other sites More sharing options...
MrBaseball34 Posted August 24, 2010 Author Share Posted August 24, 2010 That is what I was asking, how to change what I had to PS code. Link to comment Share on other sites More sharing options...
rocky Posted August 24, 2010 Share Posted August 24, 2010 I see. I thought you were unhappy with the way PrestaShop was doing queries and trying to write alternative code. Is this issue resolved now? Link to comment Share on other sites More sharing options...
MrBaseball34 Posted August 24, 2010 Author Share Posted August 24, 2010 Not yet, I haven't tested it.What is the difference between Execute and ExecuteS and sIs there a function for running INSERT, UPDATE, DELETE and the like where no resultis returned? Link to comment Share on other sites More sharing options...
rocky Posted August 24, 2010 Share Posted August 24, 2010 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. Link to comment Share on other sites More sharing options...
MrBaseball34 Posted August 24, 2010 Author Share Posted August 24, 2010 In an instance where I do this: $result = Db::getInstance()->Execute('INSERT INTO table VALUES (...)') How would I obtain the mysql_insert_id? Link to comment Share on other sites More sharing options...
MrBaseball34 Posted August 24, 2010 Author Share Posted August 24, 2010 Found it: Db::getInstance()->Insert_ID() 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