Welcome Guest, Not a member yet? Register   Sign In
MySQL or CI issue. Not sure.
#1

(This post was last modified: 03-14-2015, 12:18 PM by ozzy mandiaz.)

I'm using CI 2.2.0. I have my database set up correctly and configured in CI correctly. I have a form that validates the user input (in this case a client number - 1-5 digits all numeric, padding trimmed, etc).

in my controller, I make the following call to my model,

Code:
       $data['clients_related'] = $this->willkomen_model->getRelatedClients($data['clientnum']);

The code for getRelatedClients is below:
PHP Code:
public function getRelatedClients($clnum FALSE) {
 
       if ($clnum === FALSE) {
 
           return (array) NULL;
 
       }
 
       $query $this->db->get_where('Clients', array('ClientToBill' => $clnum));
 
       return $query->result_array();
 
   
The code this generates is correct. I see it clearly in my error message:

Code:
A Database Error Occurred

Error Number: 2014

Commands out of sync; you can't run this command now

SELECT * FROM (`Clients`) WHERE `ClientToBill` = 75

Filename: /var/www/wipinvoice/models/willkomen_model.php

Line Number: 36

According to mysql documentation, this error occurs when a query is run out of order.
Code:
If you get Commands out of sync; you can't run this command now in your client code, you are calling client functions in the wrong order.

This can happen, for example, if you are using mysql_use_result() and try to execute a new query before you have called mysql_free_result(). It can also happen if you try to execute two queries that return data without calling mysql_use_result() or mysql_store_result() in between.

This is a very simple query. Nothing APPEARS  out of order.

Anyone have any ideas?
OM...

-------------------------
And on the pedestal these words appear:
'My name is Ozymandias, king of kings:
Look on my works, ye Mighty, and despair!'
Nothing beside remains. Round the decay
Of that colossal wreck, boundless and bare
The lone and level sands stretch far away.
Reply
#2

(This post was last modified: 03-14-2015, 04:13 PM by RobertSF.)

You're right, everything looks fine. Which database driver are you using? And in the database.php file in your config directory, what is the setting for autoinit? Try reversing it and see if it makes a difference.

Also, this StackOverflow question may be helpful. Note there's a reply from a Codeigniter user.
http://stackoverflow.com/questions/61467...ommand-now
Hey, don't work without a PHP debugger. Several free IDEs have this features built in. Two are NetBeans and CodeLobster. Without a debugger, it's like you're driving with a blindfold on -- you are going to crash!
Reply
#3

Thanks for the reply.


I'm using the MySqli database driver. I read the article you mentioned  and spent some time yesterday reading through other articles.

I came across one article, http://stackoverflow.com/questions/16777...sion-class, that seems to have done the trick. And while my query isn't a sql call to a stored procedure, once I changed the _execute function in mysqli_driver.php (which I didn't really want to do), the error disappeared. 

the code is posted below.  I would recommend if you decide to change the driver file, make a backup first.
 


PHP Code:
public function _execute($sql)
{
 
   // Free result from previous query
 
   @mysqli_free_result($this->result_id);

 
   $sql $this->_prep_query($sql);

 
   // get a result code of query (), can be used for test is the query ok
 
   $retval = @mysqli_multi_query($this->conn_id$sql); 

 
   // get a first resultset
 
   $firstResult = @mysqli_store_result($this->conn_id);

 
   // free other resultsets
 
   while (@mysqli_next_result($this->conn_id)) {
 
       $result = @mysqli_store_result($this->conn_id);
 
       @mysqli_free_result($result);
 
   }

 
   // test is the error occur or not 
 
   if (!$firstResult && !@mysqli_errno($this->conn_id)) {
 
       return true;
 
   }

 
   return $firstResult

OM...

-------------------------
And on the pedestal these words appear:
'My name is Ozymandias, king of kings:
Look on my works, ye Mighty, and despair!'
Nothing beside remains. Round the decay
Of that colossal wreck, boundless and bare
The lone and level sands stretch far away.
Reply
#4

I'm glad you solved your problem. One of the answers to that question you reference suggested extending the library and creating your own MY_DB_mysqli_driver. You didn't want to go that route? Just curious.
Hey, don't work without a PHP debugger. Several free IDEs have this features built in. Two are NetBeans and CodeLobster. Without a debugger, it's like you're driving with a blindfold on -- you are going to crash!
Reply
#5

(03-15-2015, 04:09 PM)RobertSF Wrote: I'm glad you solved your problem. One of the answers to that question you reference suggested extending the library and creating your own MY_DB_mysqli_driver. You didn't want to go that route? Just curious.

I tried what was suggested. I had a time trying to figure out how to actually use that driver. I must have missed that part of the discussion. I'm just hoping that the modification doesn't affect other things. being new to codeigniter, I jumped in head first working on developing a site, and praying that the codebase was stable enough to where I wouldn't worry about it.

maybe i'll learn the code in this version sooner or later. I'm just trying to learn a bit more than the basics.

thanks again!
OM...

-------------------------
And on the pedestal these words appear:
'My name is Ozymandias, king of kings:
Look on my works, ye Mighty, and despair!'
Nothing beside remains. Round the decay
Of that colossal wreck, boundless and bare
The lone and level sands stretch far away.
Reply




Theme © iAndrew 2016 - Forum software by © MyBB