Welcome Guest, Not a member yet? Register   Sign In
Commands out of sync; you can't run this command now
#1

My problem is that I am using the DB to store session data so every time I run another query on any function that loads a page I get this error because of the session SQL write
Quote:Error Number: 2014
Commands out of sync; you can't run this command now
UPDATE `ci_sessions` SET `timestamp` = 1451263590, `data` = 'G2RpWxLrkrOG5wdf7pA8y7fCb9QIZDvqDGE9VpSw_n2zc-r28M-XZfYf7WgNWy0uDu7GHk0v-7wdUrAXseIMEVl2pP8Y8cb_JfKcpFJw1JCo66-Bo0n9M_3U8iYCdtAyFCNoMoR7F0FZD0k5dygq9oNmGkvAJhqBsbcTaWQ3oB0Vip0-VH2KydMPv8x1y3mJXBzzPUYwDv8IuBSnzAvycsTNK00FXh3WIEvErZ3rBx7-7K6JgRYgg77yeU6e5wKF' WHERE `id` = '83c9e11d794f0144fba9a728ef9ae7bf857aa60e'

So far the only fix is to add session_write_close(); to the top of the page. Problem with that is I am storing data in the sessions "Well trying to." But because I have this write_close  it destroys the session and I have nothing.

Anyone else run into this and have a fix??


Thanks in advance
Reply
#2

(12-27-2015, 06:11 PM)mike7418 Wrote: My problem is that I am using the DB to store session data so every time I run another query on any function that loads a page I get this error because of the session SQL write
Quote:Error Number: 2014
Commands out of sync; you can't run this command now
UPDATE `ci_sessions` SET `timestamp` = 1451263590, `data` = 'G2RpWxLrkrOG5wdf7pA8y7fCb9QIZDvqDGE9VpSw_n2zc-r28M-XZfYf7WgNWy0uDu7GHk0v-7wdUrAXseIMEVl2pP8Y8cb_JfKcpFJw1JCo66-Bo0n9M_3U8iYCdtAyFCNoMoR7F0FZD0k5dygq9oNmGkvAJhqBsbcTaWQ3oB0Vip0-VH2KydMPv8x1y3mJXBzzPUYwDv8IuBSnzAvycsTNK00FXh3WIEvErZ3rBx7-7K6JgRYgg77yeU6e5wKF' WHERE `id` = '83c9e11d794f0144fba9a728ef9ae7bf857aa60e'

So far the only fix is to add session_write_close(); to the top of the page. Problem with that is I am storing data in the sessions "Well trying to." But because I have this write_close  it destroys the session and I have nothing.

Anyone else run into this and have a fix??


Thanks in advance
 Ok, I read the session doc and see the explanation. I guess I'll have to turn into the session super guru to find my resolution...
Reply
#3

(12-29-2015, 06:11 AM)mike7418 Wrote:
(12-27-2015, 06:11 PM)mike7418 Wrote: My problem is that I am using the DB to store session data so every time I run another query on any function that loads a page I get this error because of the session SQL write
Quote:Error Number: 2014
Commands out of sync; you can't run this command now
UPDATE `ci_sessions` SET `timestamp` = 1451263590, `data` = 'G2RpWxLrkrOG5wdf7pA8y7fCb9QIZDvqDGE9VpSw_n2zc-r28M-XZfYf7WgNWy0uDu7GHk0v-7wdUrAXseIMEVl2pP8Y8cb_JfKcpFJw1JCo66-Bo0n9M_3U8iYCdtAyFCNoMoR7F0FZD0k5dygq9oNmGkvAJhqBsbcTaWQ3oB0Vip0-VH2KydMPv8x1y3mJXBzzPUYwDv8IuBSnzAvycsTNK00FXh3WIEvErZ3rBx7-7K6JgRYgg77yeU6e5wKF' WHERE `id` = '83c9e11d794f0144fba9a728ef9ae7bf857aa60e'

So far the only fix is to add session_write_close(); to the top of the page. Problem with that is I am storing data in the sessions "Well trying to." But because I have this write_close  it destroys the session and I have nothing.

Anyone else run into this and have a fix??


Thanks in advance
 Ok, I read the session doc and see the explanation. I guess I'll have to turn into the session super guru to find my resolution...

My whole understanding of sessions is not making sense with this problem.
Reply
#4

Maybe we could help if you could elaborate on the problem a little. You seem to be under the impression that you're running into a session concurrency issue, but the error message you've posted comes from MySQL under many different circumstances. For one, make sure you do not have pconnect enabled in your default database configuration.
Reply
#5

(This post was last modified: 12-31-2015, 06:12 AM by mike7418.)

(12-30-2015, 08:47 AM)mwhitney Wrote: Maybe we could help if you could elaborate on the problem a little. You seem to be under the impression that you're running into a session concurrency issue, but the error message you've posted comes from MySQL under many different circumstances. For one, make sure you do not have pconnect enabled in your default database configuration.

pconnect is disabled, I have a login that after the member is verified it sets session variables then redirects you back to the page you logged in from. I have checked session state right up to the redirect, then it is dropped. I have session autoloaded, here is the authentication functions

PHP Code:
function authenticate($username$password$page) {
        
//$this->load->model ( 'Db_model' );
        
        // query the db and send back result
        
$authenticate $this->authenticate_user $username$password );
        
// print_r($authenticate);
        
if (is_array $authenticate )) {
            
//echo 'returned from authenticating';
            // set session values
            
$this->set_session_values($authenticate);
            
//var_dump($this->session->all_userdata());
            //session_commit();
            
if (isset($_SESSION['user_id'])) {
 
                               // testing to ensure session state
                
$msg "Sessions were set correctly";
                
$this->do_alert($msg);
 
                               // the redirect is what will be normal after fixing the session problem
                //redirect ( base_url ( $page ), 'location', 301 );
            
} else {
                
$msg "Error: Sessions were not set correctly.";
                
$this->do_alert($msg);
            }
            
        } elseif (
preg_match '/\bError\b/i'$authenticate )) {
            
$this->do_alert $authenticate );;
        }
    }
    function 
authenticate_user($username$password) {
        
//echo 'inside of authenticate_user';
        // CALL `mike7418_greyhorse`.`sp_authenticate`(<{in_username VARCHAR(16)}>, <{in_password VARCHAR(255)}>);
        
$auth $this->db->query "CALL sp_authenticate('{$username}');" );
        
$crypt $this->config->item 'encryption_key' );
        if (
$auth->num_rows () > 0) {
            foreach ( 
$auth->result () as $key ) {
                
//$pwd = $this->encrypt->decode ( $key->password, $crypt );
                // print $pwd;
                //$pattern = '/\b' . $password . '\b/i';
                
if (password_verify($password$key->password)) {
                    
//echo "Password matched";
                    
if ($key->active == 0) {
                        return 
'Error: Member account is not currently active.';
                    } elseif (
$key->blocked == 1) {
                        return 
'Error: Member account has been blocked. Please contact customer service for further information';
                    }
                    
$session = array (
                            
'user_id' => $key->user_id,
                            
'firstname' => $key->firstname,
                            
'state' => $key->state,
                            
'zipcode' => $key->zipcode,
                            
'active' => $key->active,
                            
'user_role' => $key->user_role
                    
);
                    return 
$session;
                } else {
                    return 
"Error: Password entered does not match";
                }
            }
        } else {
            return 
'Error: Authentication failed, please try again';
        }
    } 

Everything says to run session_write_close() or session_commit() * An alias of session_write_close() because I keep getting the 'Commands out of sync'. So the first line of the function is the session_write_close(). I've tried to set a variable with the session before the close and that doesn't work either. session variable is already unset in the redirect.

PHP Code:
function index() {
$sess_fname $this->session->userdata('firstname');
//etc...

session_commit();

// the rest of the code....

Not sure if it would make a difference? But maybe I should add that I am also using Zurb Foundation CSS framework in the layout also???
Reply
#6

(This post was last modified: 12-31-2015, 11:11 AM by mwhitney. Edit Reason: semi-colon was converted into a smiley )

The first thing to try is to take the semi-colon ( ; ) out of the query:

PHP Code:
$auth $this->db->query("CALL sp_authenticate('{$username}')"); 

If that change does not fix the issue or change the error you're receiving, then you may also need to free the result before modifying the session. This should be as simple as calling $auth->free_result() before returning from authenticate_user(), but you'll have to make sure you've retrieved any data you need from the result before doing so.
Reply
#7

(This post was last modified: 12-31-2015, 04:25 PM by mike7418.)

(12-31-2015, 11:11 AM)mwhitney Wrote: The first thing to try is to take the semi-colon ( ; ) out of the query:

PHP Code:
$auth $this->db->query("CALL sp_authenticate('{$username}')"); 

If that change does not fix the issue or change the error you're receiving, then you may also need to free the result before modifying the session. This should be as simple as calling $auth->free_result() before returning from authenticate_user(), but you'll have to make sure you've retrieved any data you need from the result before doing so.

I have done both as you suggested and still does not change it. I am wondering if there is something in the php.ini I should be looking at for the sessions? Like I said it holds on to the session values I am setting right up until I do the redirect back to the page that submitted the logon. When I check the session values on that page all I get is the session id which matches the last check of the session values at
PHP Code:
var_dump($this->session->all_userdata());
//session_commit();
if (isset($_SESSION['user_id'])) {
... 
I display all of the userdata, then one last check for the $_SESSION['user_id']  Then it redirects. But at the redirected page, the only session variable is the session id which matches the session id from all_userdata() ???
Reply
#8

You need the next result to proceed. Maybe something like this right after your call to the procedure:


PHP Code:
mysqli_next_result$this->db->conn_id ); 
Reply
#9

(12-31-2015, 04:24 PM)mike7418 Wrote:
(12-31-2015, 11:11 AM)mwhitney Wrote: The first thing to try is to take the semi-colon ( ; ) out of the query:

PHP Code:
$auth $this->db->query("CALL sp_authenticate('{$username}')"); 

If that change does not fix the issue or change the error you're receiving, then you may also need to free the result before modifying the session. This should be as simple as calling $auth->free_result() before returning from authenticate_user(), but you'll have to make sure you've retrieved any data you need from the result before doing so.

I have done both as you suggested and still does not change it. I am wondering if there is something in the php.ini I should be looking at for the sessions? Like I said it holds on to the session values I am setting right up until I do the redirect back to the page that submitted the logon. When I check the session values on that page all I get is the session id which matches the last check of the session values at
PHP Code:
var_dump($this->session->all_userdata());
//session_commit();
if (isset($_SESSION['user_id'])) {
... 
I display all of the userdata, then one last check for the $_SESSION['user_id']  Then it redirects. But at the redirected page, the only session variable is the session id which matches the session id from all_userdata() ???

Well I found part of the problem. Apparently do not try setting your session variables in a model? I switched the sessions to files, moved the session write to the controller and it works. But it still doesn't like the database? But at 2am I'm not worrying about it... Thanks for everyone's help
Reply
#10

See this page about the Commands Out of Sync error:
http://community-auth.com/blog-posts/com...procedures
Reply




Theme © iAndrew 2016 - Forum software by © MyBB