Tuesday, May 14, 2013

function mysql_connect

The most important function that is used in the php coding is mysql_connect .

This is function used to connect Mysql server with Apache server (PHP).

The syntax for it goes as

mysql_connect ( localhost,username,password)

where the localhost refers to Mysql HOST

username :Mysql username
password ;Mysql password

Example of mysql_connect

<?php
    $link = mysql_connect("localhost", "username", "password")
        or die("Could not connect");
    print ("Connected successfully");
    mysql_close($link);
?>


Similar function which is used for connecting the Mysql server is mysql_pconnect

Mysql_pconnect establishes a persistent connection

In Mysql_connect after the script that calls it has finished it will be closed. but mysql_pconnect will continue to hold the connection until it is closed manually by the user. 

No comments:

Post a Comment