Join the social network of Tech Nerds, increase skill rank, get work, manage projects...
 
  • Connect to MySQL in PHP

    • 0
    • 1
    • 0
    • 0
    • 0
    • 0
    • 0
    • 0
    • 103
    Comment on it

    In PHP, To perform any data task in MySQL database , first we have to connect MySql database to local server

    This can be done as :

    <?php
    $servername = "localhost";
    $username = "username";
    $password = "password";
    
    // Create connection
    $conn = new mysqli($servername, $username, $password);
    
    // Check connection
    if ($conn->connect_error) {
        die("Connection failed: " . $conn->connect_error);
    } 
    echo "Connected successfully";
    ?>
    

    We have to specify the servername, username and password to get connection from the database. Then by using function mysqli(), we passed those variable as arguments. if there would be any error in connection, then it will be displayed and the execution halts or else it will show "Connected successfully" message.

 0 Comment(s)

Sign In
                           OR                           
                           OR                           
Register

Sign up using

                           OR                           
Forgot Password
Fill out the form below and instructions to reset your password will be emailed to you:
Reset Password
Fill out the form below and reset your password: