Quantcast
Channel: PHP Freaks: PHP Help
Viewing all articles
Browse latest Browse all 13200

Handling my connection variable for login script use

$
0
0
Hi all,
 
Currently I am using 
 
    $con=mysqli_connect("x","x","x","x");
 
On my login page to satisfy the the connection variable for mysqli_real_escape_string($con, $x)
 
This works OK. However I have been told it's very bad to put my connection information on my login page, and I must change it. 
 
So I have moved  $con=mysqli_connect("x","x","x","x"); into my class method, and then called for it like so :
 
$con=new dbclass();
$con->openDB();
 
 
However despite this, mysqli_real_escape is returning :
 
    Warning: mysqli_real_escape_string() expects parameter 1 to be mysqli, object given in C:\xampp\htdocs\c\login.php on line 103
    
    Warning: mysqli_real_escape_string() expects parameter 1 to be mysqli, object given in C:\xampp\htdocs\c\login.php on line 104
    
    Warning: mysqli_query() expects parameter 1 to be mysqli, object given in C:\xampp\htdocs\c\login.php on line 109
    
    Warning: mysqli_fetch_array() expects parameter 1 to be mysqli_result, null given in C:\xampp\htdocs\c\login.php on line 111
    Acess denied, wrong username or password?
This is the method I'm using to do this.
 
    function openDB() {
            
      include("/assets/configs/db_config.php");
$conn = mysqli_connect('x', 'x', 'x', 'xxt');
    
    // 1. Create a database connection
    if (!$conn)
    {
        $this->error_msg = "connection error could not connect to the database:! ";  
        return false;
    }
    $this->conn = $conn;
    return true;
    }
 
Can anyone make any suggestions on what I can do. Any code examples based on my code would also be very useful.
 
Thanks,
Keith Tyrell
 

Viewing all articles
Browse latest Browse all 13200

Trending Articles