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.
[ 0 ] Comments