SitePoint Sponsor

User Tag List

Results 1 to 6 of 6

Thread: PHP MySql error

  1. #1
    SitePoint Addict
    Join Date
    Nov 2007
    Location
    California
    Posts
    357
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    PHP MySql error

    Need help on this particular error. Using Apache/2.2.11, PHP Version 5.2.8 and MySQL client version: 5.1.30. On the first try, it works. That's when the browser is still newly opened. Anything after that won't work.

    Getting the following errors.

    Warning: mysqli_errno() [function.mysqli-errno]: Couldn't fetch mysqli in C:\xampp\htdocs\ch11\ShoppingCart.php on line 31

    Warning: mysqli_error() [function.mysqli-error]: Couldn't fetch mysqli in C:\xampp\htdocs\ch11\ShoppingCart.php on line 32

    Unable to select the database.

    Error code :
    Warning: mysqli::close() [mysqli.close]: Couldn't fetch mysqli in C:\xampp\htdocs\ch11\ShoppingCart.php on line 18


    Here are the codes:

    function __construct() {
    $this->DBConnect = @new mysqli("localhost", "oliver", "lopez1");
    if(mysqli_connect_errno())
    die("<p>Unable to connect to the database server. </p>"
    . "<p>Error code " . mysqli_connect_errno()
    . ": " . mysqli_connect_error()) . "</p>";
    }

    function __destruct() {
    Line 18 $this->DBConnect->close();
    }



    function __wakeup() {
    $this->DBCOnnect=new mysqli("localhost", "oliver", "lopez1");
    if(mysqli_connect_errno())
    die("<p>Unable to connect to the database server.</p>"
    . "<p>Error code " . mysqli_connect_errno()
    . ": " . mysqli_connect_error()) . "</p>";
    @$this->DBConnect->select_db($this->DBName)
    Or die("<p>Unable to select the database.</p>"
    Line 31 . "<p>Error code " . mysqli_errno($this->DBConnect)
    Line 32 . ": " . mysqli_error($this->DBConnect)) . "</p>";
    }

    Tried changing the __destruct function with this, but did not work.
    function __destruct() {
    Line 18 $this->DBConnect->close();
    }

    and it produced the two errors, without the last error on line 18

    Warning: mysqli_errno() [function.mysqli-errno]: Couldn't fetch mysqli in C:\xampp\htdocs\ch11\ShoppingCart.php on line 32

    Warning: mysqli_error() [function.mysqli-error]: Couldn't fetch mysqli in C:\xampp\htdocs\ch11\ShoppingCart.php on line 33

    Unable to select the database.

    Error code :

    How can this problem be solved? Any hints?

    Thanks and best regards,
    Oliver

  2. #2
    SitePoint Evangelist
    Join Date
    Aug 2007
    Posts
    566
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Unable to select the database.
    This seems to mean that you either have a db connection problem, or that the database (contained as a property of the db object, "$this->DBName") doesn't exists on your local server.

    Did you transferred a copy of the db, or you just downloaded the files of your site ?

  3. #3
    SitePoint Enthusiast
    Join Date
    Feb 2009
    Location
    Athens, Greece
    Posts
    68
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Make sure the database name, username and password are correct.

  4. #4
    SitePoint Member
    Join Date
    Sep 2008
    Posts
    15
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    It's weird that it only works the first time.. what browser are you using?

  5. #5
    SitePoint Guru
    Join Date
    Sep 2008
    Location
    Dubai
    Posts
    971
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    What you mean it work for only the first time? like load the page, it works, then press refresh, it not works ?

    Anyway do this check list:

    Check your links.

    Check your url that produces the uri for querying.

    Check session and cookie that might play apart in your "if" condition, which constructs your sql query.

  6. #6
    SitePoint Addict
    Join Date
    Nov 2007
    Location
    California
    Posts
    357
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Hi, thanks for the reply. Found the culprit

    $this->DBCOnnect=new mysqli("localhost", "oliver", "lopez1");

    which should be

    $this->DBConnect=new mysqli("localhost", "oliver", "lopez1");

    DBCOnnect to DBconnect


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
  •