Tuesday, November 23, 2010

Let Learn PHP (Basic) - Lesson 2

Working with PHP always need a connection to the database..
Coz that make it easier to build an interactive Web Application.

Here some of the example that you can use:-

Example 1

<?php
$hostname_conn = "localhost";
$database_conn = "my_db";
$username_conn = "root";
$password_conn = "abc123";
$conn = mysql_pconnect($hostname_conn, $username_conn, $password_conn) or trigger_error(mysql_error(),E_USER_ERROR);
?>

Example 2

<?php
$con = mysql_connect("localhost","root","abc123");
if (!$con)
{
die('Could not connect: ' . mysql_error());
}
?>
  
Example 3

<?php
$dbhost = 'localhost';
$dbuser = 'root';
$dbpass = 'password';
$conn = mysql_connect($dbhost, $dbuser, $dbpass) or die('Error connecting to mysql');
$dbname = 'my_db';
mysql_select_db($dbname);
?>

3 comments:

LinkWithin

Related Posts Plugin for WordPress, Blogger...