SitePoint Sponsor

User Tag List

Results 1 to 7 of 7
  1. #1
    SitePoint Guru GamerZ's Avatar
    Join Date
    Nov 2001
    Location
    Singapore
    Posts
    617
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    mysql_affected_rows(): A link to the server could not be established

    Good evening guys,

    One of my users have encountered this error below
    Warning: mysql_affected_rows() [function.mysql-affected-rows]: A link to the server could not be established in /home/sites/dancemaster.org.uk/public_html/news/wp-includes/wp-db.php on line 183
    Any idea how to solve it?

    Thank you

  2. #2
    SitePoint Wizard silver trophybronze trophy Cups's Avatar
    Join Date
    Oct 2006
    Location
    France, deep rural.
    Posts
    6,869
    Mentioned
    17 Post(s)
    Tagged
    1 Thread(s)
    Looks like a word press issue?

    If you are using WordPress why not try their forum?

    OR tell us what is on line 183 of wp-db.php

  3. #3
    Programming Team silver trophybronze trophy
    Mittineague's Avatar
    Join Date
    Jul 2005
    Location
    West Springfield, Massachusetts
    Posts
    17,228
    Mentioned
    194 Post(s)
    Tagged
    2 Thread(s)

    wp db error

    In WP ver 2.1.2 that section of code is in the query function of the wpdb class.
    PHP Code:
            if ( preg_match("/^\\s*(insert|delete|update|replace) /i",$query) ) {
                
    $this->rows_affected mysql_affected_rows();
                
    // Take note of the insert_id
                
    if ( preg_match("/^\\s*(insert|replace) /i",$query) ) {
                    
    $this->insert_id mysql_insert_id($this->dbh);
                }
                
    // Return number of rows affected
                
    $return_val $this->rows_affected
    Maybe you could add the error suppressor "@" to the mysql function calls? Or change the lines to something like
    $ = () ? () : 0;
    and/or
    $ = () ? () : NULL;

  4. #4
    SitePoint Guru GamerZ's Avatar
    Join Date
    Nov 2001
    Location
    Singapore
    Posts
    617
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Thanks for the reply guys. But is there a general solution for this? Because I have tested in on 2 different live server, and 2 different localhost and these 4 servers do not have this problem. Is it a mysql problem?

  5. #5
    Programming Team silver trophybronze trophy
    Mittineague's Avatar
    Join Date
    Jul 2005
    Location
    West Springfield, Massachusetts
    Posts
    17,228
    Mentioned
    194 Post(s)
    Tagged
    2 Thread(s)

    db server

    I don't think you can control when there will be a database server error. But you can do something about what happens when there is an error. AFAIK big companies have multiple servers so if one fails a back-up handles things. I don't know how they "lock" multiple threads and maintain multiple records between them. Anyway, for a non-big-business I think just handling the error gracefully would be good enough. I have been working on an error reporting plugin for WP, but at the present it's more of a hack (I'm still a newbie WP plugin writing-wise).

  6. #6
    SitePoint Guru GamerZ's Avatar
    Join Date
    Nov 2001
    Location
    Singapore
    Posts
    617
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    i see, thank you, i guess i just suppress the error. lol

  7. #7
    Programming Team silver trophybronze trophy
    Mittineague's Avatar
    Join Date
    Jul 2005
    Location
    West Springfield, Massachusetts
    Posts
    17,228
    Mentioned
    194 Post(s)
    Tagged
    2 Thread(s)

    bail

    On closer look at the file, I see that the class has earlier mysql function calls that are suppressed, but have custom error messages that are passed to it's bail function. eg.
    PHP Code:
            if (!$this->dbh) {
                
    $this->bail("
    <h1>Error establishing a database connection</h1>
    ...... 
    PHP Code:
        /**
         * Wraps fatal errors in a nice header and footer and dies.
         * @param string $message
         */
        
    function bail($message) { // Just wraps errors in a nice header and footer
    ........ 
    It might be nice to show your users something. I can't think of why the file doesn't do the message thing consistently, unless whoever wrote it figured all errors would occur before it got that far.


Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •