mysql_connect()

To connect to a database, a connection handle (common name for the array containing the connection variables) must be assigned from the mysql_connect() function:

 

$connectionHandle = mysql_connect( $server, $user, $passwd ) ;

 

$server, $user, $passwd can be set in php.ini, though more common to include from separate file, e.g.:

 

<?php
	$server = 'localhost:3060' ; //default port is 3060, doesn't need to be specified
	$user = 'dbUser' ; //name of the db user
	$passwd = 'secret' ; //password of the db user
?>

 

This can now be called from the connecting script:

 

<?php
	include("/var/www/dbConfig.php"); //get the connection variables

	$connection = mysql_connect( $server, $user, $passwd ) ; //connect to the database server

	/* MORE CODE TO BE INSERTED HERE */

	mysql_close( $connection ) ;
?>

Leave a Reply