PHP MySQL Database Connection Example

PHP MySQL Database Connection Example


Posted in : PHP Posted on : February 3, 2011 at 4:40 PM Comments : [ 0 ]

In this tutorial, you can learn how to connect php application with mysql database server.

PHP MySQL Database Connection Example:

In this tutorial, you can learn how to connect php application with mysql database server. PHP gives mysql_connect() function for database connection.

Syntax:

mysql_connect(url, username, password)

where,

url is specified the server to connect. Default value is "localhost:3306".

username is the mysql user name for log in with mysql server.

password is the mysql password for log in with mysql server.

This example show the connectivity between php and mysql server.

Example:

<?php
$connection = mysql_connect("localhost", "root", "root");
if (!$connection)
{
die('PHP Mysql database connection could not connect: ' . mysql_error());
}
else{
echo "PHP MySql database connection Created.";
}
?>

Output:

PHP MySql database connection Created.

Download Example Code

Go to Topic «PreviousHomeNext»

Your Comment:


Your Name (*) :
Your Email :
Subject (*):
Your Comment (*):
  Reload Image
 
 

 
Tutorial Topics