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


THEFT – this company stole money, its not the first time reviews have been submitted with the same information. its fraud pure and simple. if you join you will be scammed…….. any positive reviews on this site are from employees or scouts, who publish great but totally untrue reviews….. this information is true, Β£270 taken from my account without consent after i cancelled my subscription……. THEFT AND FRAUD…………. Kevin, South wales


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 to Connect to MySQL From a PHP Document
3 Ways to Connect to MySQL Using PHP
MySQL Tutorial – Connect
PHP/MySQL Tutorial
Connect to Your MySQL Database using PHP
PHP Connect to the MySQL Server

ProgrammingKnowledge

21 Comments
  • ForgottenLegends OfTomorrow
    Posted at 16:43h, 25 June

    mysql_connect() is depecrated. use mysqli_connect() instead πŸ™‚

  • Abbas Basheer
    Posted at 07:55h, 18 July

    helpful but i think a but old tutorial……

  • Veerendra Chandaluri
    Posted at 09:13h, 26 July

    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

  • Dilshard
    Posted at 10:28h, 28 July

    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';
    }

  • Skyflower traders
    Posted at 08:31h, 28 September

    Fatal error: Uncaught Error: Call to undefined function mysql_select_db() in C showing this error help me

  • Pushpa Ray
    Posted at 10:58h, 30 September

    It's showing an error. Please tell me why so? It's showing that Filezilla is not found. And phpmyadmin showing as access denied

  • Wai Chan
    Posted at 04:37h, 04 October

    Anyone who is facing regarding the error "Call to undefined function mysql_connect()" try using this
    <?php
    $dbhost = 'localhost';
    $user ='root';
    $pass ='';
    $db ='testdb'; // databasename
    $conn=mysqli_connect("$dbhost","$user","$pass","$db");
    echo "Connected";

    ?>

  • sankhyadip choudhury
    Posted at 16:32h, 28 October

    sir i tried to change the password from phpmyadmin but suddenly it disconnected and strated showing the following message

    Error

    MySQL said: Documentation
    #1045 – Access denied for user 'root'@'localhost' (using password: NO)
    mysqli_real_connect(): (HY000/1045): Access denied for user 'root'@'localhost' (using password: NO)
    phpMyAdmin tried to connect to the MySQL server, and the server rejected the connection. You should check the host, username and password in your configuration and make sure that they correspond to the information given by the administrator of the MySQL server.

  • sankhyadip choudhury
    Posted at 16:34h, 28 October

    i had not set any password earlier

  • Dishant patel
    Posted at 13:18h, 07 December

    mysql_connect() is depecrated. use mysqli_connect() instead πŸ™‚

  • Hogr Nawzad
    Posted at 11:26h, 09 January

    goood

  • Amit pandey
    Posted at 13:00h, 28 January

    Whenever i try to run the code i get this error please anyone help me.
    Uncaught Error: Call to undefined function mysql_comment() in C:xampphtdocsconnect.php:7 Stack trace: #0 {main} thrown in C:xampphtdocsconnect.php on line 7

  • Isuru Dayananda
    Posted at 18:31h, 01 March

    I got this warning please help me.Warning: mysqli_connect(): (HY000/2002): No connection could be made because the target machine actively refused it. in C:wampwwwcidatabaseconnect.php on line 8

  • arjun kumar
    Posted at 08:15h, 18 March

    how to resolve
    mysql_native_password!ΓΏβ€ž#08S01Got packets out of order
    error please help me
    any one

  • Usman Choudry
    Posted at 08:25h, 01 April

    Sir this is old way pls update this video

  • Pooja Singh
    Posted at 02:39h, 15 April

    Showing error

  • Sunny Rock8
    Posted at 14:53h, 24 April

    i'm not getting the local host ? pls help!!

  • MOhammEd Mzml
    Posted at 06:25h, 03 June

    i'm using ubuntu.
    i'm getting this error "localhost is currently unable to handle this request.
    HTTP ERROR 500" please help me

  • Pratap Karki
    Posted at 17:13h, 04 July

    What if we didn't set password during install?

  • RAJESH upadhyaya
    Posted at 11:42h, 08 September

    Sir I hv installed campo and running successfully,I have changed the password through phpmyadmin-user account-root local host-edit priveledge.But connection through PHP is giving error ,I have tried as per your codes and with the changed password.Please clear the bug

  • Emaduddin Sarwar
    Posted at 12:13h, 12 September

    It giving me this error
    "Fatal error: Uncaught Error: Call to undefined function mysql_connect() in C:xampphtdocsWorkingsdatabaseconnect.php:7 Stack trace: #0 {main} thrown in C:xampphtdocsWorkingsdatabaseconnect.php on line 7"