Sabtu, 10 Maret 2012

Connection PHP to MySQL

In Dynamic web development is necessary to a database. Prior information about the mysql functions in PHP it's good you know what it is about the database. The database I use is MySQL. MySQL can be downloaded for free at the url http://www.mysql.com/downloads/. Or if you use an application such as XAMPP package you do not need download mysql as the MySQL software is already there.
we will create a connection PHP to MySQL script

<?php
$hostmysql = “localhost”;
$username = “mysql_username”;
$password = “mysql_password”;
$database = “name_database”;

$conn = mysql_connect(”$hostmysql”,”$username”,”$password”);
if (!$conn) die (”Connection failed”);
mysql_select_db($database,$conn) or die (”Database Not Found”); 

?>

Explanation Script PHP connection to MySQL:
a. mysql_connect is used to make connections using PHP to MySQL server. Data for the hostname, MySQL username, and password used has been declared by the variable $hostmysql, $username, $password.
Writing the script will be equal to:
mysql_connect ("localhost", "username", "password");


b. mysql_select_db used to select the database to be used.

c. if (!$conn) die ("Failed Connecting"); if there is a failure in connecting (!$conn), it will display an error message Failed to Make Connections 
  

good luck  

Tidak ada komentar:

Posting Komentar