PHP Tutorial for Beginners 30 # How to connect to MySQL database using PHP




PHP Connect to the MySQL Server connecting to mysql database php android connecting to php mysql How to access a MySQL database with PHP code How …

Original source


22 responses to “PHP Tutorial for Beginners 30 # How to connect to MySQL database using PHP”

  1. latest connection code is here,

    $host = 'localhost';
    $user = 'root';
    $password = '';
    $db = 'test';

    $con = @mysqli_connect($host, $user, $password, $db);

    if (!$con)
    {
    die('cannot connect to the database!');
    }
    else
    {
    @mysqli_select_db($con, "test");
    echo 'success';
    }

  2. i got this error (i am using windows 10)
    Fatal error: Uncaught Error: Call to undefined function mysql_connect() in F:xampphtdocsphpexamplesdatabaseconnect.php:9 Stack trace: #0 {main} thrown in F:xampphtdocsphpexamplesdatabaseconnect.php on line 9

  3. i was getting error 500 in my chrome (Ubuntu 16.04 LTS)
    and firefox shows just a white screen

    everything worked and including echo, except "mysql_connect"

    at last, it it was "mysqli_connect" in php7.0

    that "i" wasted my 5 days (reinstalled ubuntu, ,lamp ,phpmyadmin…. and running many commands in terminal)

    i am writing that, because it can save 5 days of someone.. lol 😛

  4. <?php
    $mysql_host='localhost';
    $mysql_user='root';
    $mysql_password='';

    if(!@mysql_connect($mysql_host,$mysql_user,$mysql_password))
    {

    die('cannot connect to database');
    }

    else

    if(@mysql_select_db('login'));
    {
    echo 'connection success';

    }

    ?>

Leave a Reply