> connecting mysql with php ~ Online tutorial

connecting mysql with php

Connecting to a MySQL Database
Before you can access and work with data in a database, you must create a connection to the database.
In PHP, this is done with the mysql_connect() function.

Syntax


mysql_connect(servername,username,password);
Parameter Description
  • servername Optional. Specifies the server to connect to. Default value is "localhost:3306"
  • username Optional. Specifies the username to log in with. Default value is the name ofthe user that owns the server process
  • password Optional. Specifies the password to log in with. Default is ""
Note:
There are more available parameters, but the ones listed above are the most important.

Example
In the following example we store the connection in a variable ($con) for later use in the script.
The "die" part will be executed if the connection fails:

  • <?php
    $con = mysql_connect("localhost","root","");
    if (!$con)
    {
    die('Could not connect: ' . mysql_error());
    }
    // some code
    ?>
  • Please Give Us Your 1 Minute In Sharing This Post!
    Please Give Us Your 1 Minute In Sharing This Post!
    SOCIALIZE IT →
    FOLLOW US →
    SHARE IT →
    Powered By: BloggerYard.Com

    0 comments: