cancel
Showing results for 
Show  only  | Search instead for 
Did you mean: 

database connection using mysql

i have created a database chinnour,table stud. I want to connect the database with the php code.

in cpanel i have written the php code.

<?php
    //Sample Database Connection Syntax for PHP and MySQL.
    
    //Connect To Database
    
    //$hostname="127.0.0.1:3306";
    $hostname="43.255.154.42";
    $username="bps1";
    $password="Shahjahanpur1*";
    $dbname="chinnour";
    $usertable="stud";
    $yourfield = "empid";
    echo "12 ";
    mysql_connect($hostname,$username, $password) or die ("<html><script language='JavaScript'>alert('Unable to connect to database! Please try again later.'),history.go(-1)</script></html>");
    echo "2 ";
    mysql_select_db($dbname);
    
    # Check If Record Exists
    
    $query = "SELECT * FROM $usertable";
    
    $result = mysql_query($query);
    
    if($result){
        while($row = mysql_fetch_array($result)){
            $name = $row["$yourfield"];
            echo "Name: ".$name."<br/>";
        }
    }
?>