Saturday, 1 August 2009

Making a connection page

After designing and inserting data into the hosting database, I use PHP scripting to connect with the database by script below:

$dbConn = mysql_connect ($dbHost, $dbUser, $dbPass) or die ('MySQL connect failed. ' . mysql_error());

The function mysql_connect() means to connect with MySQL database. In the function, a variable $dbHost to specify the server to connect with, $dbUser to specifies the username to log in with and $dbPass to specifies the password to log in with. If these variables are not matched with Hosting server authentication, then an error message will be shown by mysql_error.

I then use mysql_select_db() to make a chosen database active

mysql_select_db($dbName) or die('Cannot select database. ' . mysql_error());

with variable $dbName to specify the database name.

No comments:

Post a Comment