Forum Moderators: coopster

Message Too Old, No Replies

question about mysql to mysqli conversion in php.

         

nelsonm

6:45 am on Feb 11, 2012 (gmt 0)

10+ Year Member



hi all,

I've been using standard php/mysql and I wanted to try my hand at stored procedures so i modified my old php script to use mysql stored procedures.


<?PHP
$open = mysql_connect($dbConfig['dbServer'], $dbConfig['dbUser'], $dbConfig['dbPassword'], true);
$set = mysql_select_db($dbConfig['dbDatabase'], $open)
.
.
.
// run the query.
if(!$result = mysql_query('call selectworkorders("'.$where.'","'.$order.'")')){
logMsg(__LINE__,'E','Could not execute query: '.mysql_error()); exit;
}
?>


The stored procedure is working fine but i get an error:
Could not execute query: Commands out of sync; you can't run this command now.

I believe this is due to stored procedures returning multiple sets - a result set and a data set. After some research, it appears i need to convert my php script from MySQL to MySQLi in order to get this to work.


My questions are:

1. Is there a way to get this to work the way it is without converting to MySQLi?

2. Is MySQLi (the wave of the future) what i should be using in all future php scripts?

3. If so, does it matter whether i use procedural or oo php?


thanks.

coopster

3:29 am on Feb 15, 2012 (gmt 0)

WebmasterWorld Administrator 10+ Year Member



I cannot respond to the first question. Once I considered advanced (at the time) MySQL APIs I decided to use the newer MySQL API features in PHP.

I switched over to mysqli quite some time ago and haven't looked back. I would seriously consider it for future development if I were you. You can still use procedural if you are comfortable in that playground but the object-based interface offers more flexibility/options if you ask me.

nelsonm

5:04 am on Feb 15, 2012 (gmt 0)

10+ Year Member



coopster,

yes, i'm coming to that conclusion as well - but old habits die hard. I have started converting one of my php scripts and have solved the sync problem. I figure once i spend some time fiddling with sp's and classes, i'll warn up to it more.

thanks.