Results 1 to 2 of 2

Thread: PHP and MySQL Error handling problems

  1. #1
    Join Date
    Jul 2005
    Posts
    26

    PHP and MySQL Error handling problems

    Hello everyone,I am running PHP 5 with Apache on Windows Pro XP, I have the following code and it keeps giving me errors, the code is for a MySQL 4.1 database connection system.
    It keeps giving me the Error:
    Warning: mysqli_error() expects parameter 1 to be mysqli, boolean given in D:\PATH\DBConnectE.php on line 30

    We could not query the database, please try again later,
    SQL Connect Num=1
    Line 30 is :echo(mysqli_error($this->Query)."<br /> We could not query the database, please try again later,<br /> SQL Connect Num=$this->DBConnectNum");
    PHP Code:
    class DB
        
    {
    var 
    $Conn;        
    var 
    $DBConnectNum;
    #var $Query;
            
    function __construct($DBHost="localhost",$DBUsername="root",$DBPassword="****")    
            {
            
    $this->DBConnectNum=1;
            
    $this->Connmysqli_connect($DBHost,$DBUsername,$DBPassword) or die(mysqli_error($Conn)."<br />Database is not available at this moment, please try again later,<br /> SQL Connect Num=$DBConnectNum ");
            
            
    $DBSmysqli_select_db($this->Conn,"membersp") or die(mysqli_error($DBS)."<br />The required database is not available, please try again later,<br /> SQL Connect Num=$DBConnectNum");
            
            return 
    $this->Conn;
            }    
            
            function 
    SelectDB($DB)
            {
            
            
    $DBSmysqli_select_db($this->Conn,$DB)  or die(mysqli_error($DBS)."<br />The required database is not available, please try again later,<br /> SQL Connect Num=$DBConnectNum");
            return 
    $DBS;
            }    
            function 
    Query($SQL)
            {
            
            
    $this->Query=mysqli_query($this->Conn,$SQL);
            if(!
    $this->Query)
                {
                echo(
    mysqli_error($this->Query)."<br /> We could not query the database, please try again later,<br /> SQL Connect Num=$this->DBConnectNum");
                exit();
                }
            
    $this->DBConnectNum++;
            }
            function 
    QueryInfo($Type="Array")
                {
            if(
    $Type="Array")
                {
                
    $Array=mysqli_fetch_array($this->Query);
                return 
    $Array;
                }
            if(
    $Type="NumRow")
                {
                
    $NumRowmysqli_num_rows($this->Query);
                return 
    $NumRow;
                }
        
            
            }
            function 
    __destruct()
            {
            global 
    $Conn;
            
    mysqli_close($this->Conn);
            }    
            
        } 
    Thanks in advance...

  2. #2
    Join Date
    Jul 2005
    Posts
    26
    Oh Woops, sorry guys I fixed the problem, turns out in mysqli_error you need to put the $Conn, not the $Query

Posting Permissions

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