Posted The: 28/04/2009 At: 13:39
The first thing we need to do before we can use MySQL, is to connect to the database. To do this, we will use something like the below code.
$MYSQL_Host = 'localhost'; // The host to connect to, usually this is the localhost. $MYSQL_Uname = 'MySite_com'; // YourUserName $MYSQL_Pword = 'MyPassword'; // YourPassWord $MYSQL_Dbase = 'MySite_com'; // YourDatabase $Connection = mysql_connect($MYSQL_Host, $MYSQL_Uname, $MYSQL_Pword); $DB_selected = mysql_select_db($MYSQL_Dbase, $Connection);
The $Connection variable is used to refer to the connection, as we did when selecting the Database.
$DB_selected = mysql_select_db($MYSQL_Dbase, $Connection);
Selecting which database to use, makes sure that subsequent calls to mysql_query() will be performed on the active database.
We do not need to refer to the database in our queries, as the active database automatically is selected.
Comments: [0]
© Brugbart Webdesign