Jump to content

Recommended Posts

Hey guys,

 

I have just worked out why some of my queries are failing! :) --

[19-Jan-2010 01:22:20] PHP Warning:  mysql_num_rows(): supplied argument is not a valid MySQL result resource in /home/#####/public_html/#####/Project/lib.php on line 634
[19-Jan-2010 01:22:20] PHP Warning:  mysql_num_rows(): supplied argument is not a valid MySQL result resource in /home/#####/public_html/#####/Project/lib.php on line 644
[19-Jan-2010 01:22:33] MySQL server has gone away in <strong>retrieve_data</strong> called from <strong>/home/#####/public_html/#####/Project/lib.php</strong> on line <strong>355</strong>
<br />error handler

 

MySQL server somehow flutters away in the breeze and I think it's because I am doing too many calls/connections at once... Does anyone know if theres a simple way of just using the existing connection? My function is below...

 

I was just wondering something along the logical lines of "If MYSQL Server already connected, do not create a new one, use existing..."

or am I better off throwing a mysql_close($conn) every function that calls it?

 

Cheers!

 

//Connect to DATABASE
function get_db_conn() {
  $conn = mysql_connect($GLOBALS['db_host'], $GLOBALS['db_user'], $GLOBALS['db_pass']);
          mysql_select_db($GLOBALS['db_name'], $conn);  
  return $conn;
}

Link to comment
https://forums.phpfreaks.com/topic/188994-mysql-server-has-gone-away/
Share on other sites

More code as requested... :)

 

 function retrieve_data( $check_id ) {
    if ( $check_id == NULL ) {
        die( 'No ID Submitted. Please notify the me via (augrunt@hotmail.com) about what page you were on and what you tried to do before you saw this error as I am trying to find out what is wrong. Thank you' );
    }
    get_db_conn();
    global $first_time;
    $result = mysql_query( "SELECT * FROM users where user_id='$check_id'" ) or error( mysql_error() );
    $row = mysql_fetch_array( $result );
    if ( $row[ 'user_id' ] == NULL ) {
        create_first_time( $check_id );
        //echo '<center><fb:explanation message="Welcome First-time User! =]" /></center>';
        try {
            send_notification( $check_id, 'Welcome <fb:name firstnameonly="true" uid="' . $check_id . '" useyou="false"/> to <a href="http://apps.facebook.com/mytwitteraccount/portal.php">My Account (is @ Twitter)</a>. Make sure you add My Account (is @ Twitter) to your Profile to ensure everyone knows where to find you on Twitter!', 'app_to_user' );
        }
        catch ( Exception $e ) {
								echo 'Caught exception: ', $e->getMessage(), "\n";
								error_log('Error #' . $e->getCode() . ': ' . $e->getMessage() );
        }
        $first_time == true;
    }
close_db_conn( get_db_conn() );
    return $row;
}

 

//Handles FBML that posts to Info boxes
function info_box_post( $user_id, $twitter_username ) {
    global $facebook;
    //get ready to take some data
    $retrieval     = retrieve_data( $user_id );
    //handle the data
    $twitter_image = $retrieval[ 'twitter_image' ];
    if ( $twitter_image == NULL ) {
        $twitter_image = 'http://static.twitter.com/images/default_profile_normal.png';
    }
    //continue
    $info_fields = array(
         array(
             'field' => 'Username',
            'items' => array(
                 array(
                     'label' => '@' . $twitter_username . '',
                    'image' => $twitter_image,
                    'description' => 'Known as ' . $twitter_username . 'on Twitter!',
                    //'image'=> 'http://foo.bar/Mountain_goats.jpg',
                    'link' => 'http://www.twitter.com/' . $twitter_username . '' 
                ) 
            ) 
        ) 
    );
    try {
        $facebook->api_client->call_method( 'facebook.profile.setInfo', array(
             'uid' => $user_id,
            'type' => '1',
            'title' => 'My Twitter Account',
            'info_fields' => json_encode( $info_fields ) 
        ) );
    }
    catch ( Exception $e ) {
        echo 'Caught exception: ', $e->getMessage(), "\n";
	error_log('Error #' . $e->getCode() . ': ' . $e->getMessage() );
    }
}

 

The function that continues to make the MySQL fly away... I have made an adjustment, I have moved the close_db_conn(get_db_conn()) where before it was "after" the return, which I recall does not get executed since "return" is the last thing it does, correct?

 

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.