MySQL Forums
Forum List  »  PHP

Connecting to MySQL on numerous pages
Posted by: Mike C-boom
Date: March 11, 2012 11:31AM


Learning PHP and MySQL...I have a test website that I am building that includes a query to the same MySQL database in pretty much every page. As a result, the following code is part of my new page template.

What I don't know is if there is a more prefered method of handling this connection. Am I doing this right or can I do it better? Looking forward to any comments/discussion. This has been bugging me for quite some time now.



if (!extension_loaded('mysql')) {
if (!dl('php_mysql.dll')) {
echo "Failed to load dynamic library php_mysql.dll
$username = "username";
$password = "password";
$hostname = "";
$dbh = mysql_connect($hostname, $username, $password)
or die("Unable to connect to MySQL.");
//print "Connected to MySQL<br>";
$selected = mysql_select_db("mysql_db",$dbh)
or die("Could not select mysql_db");

//SOME MySQL Query
//SOME Return From Query and post to website


Options: ReplyQuote

Written By
Connecting to MySQL on numerous pages
March 11, 2012 11:31AM

Sorry, you can't reply to this topic. It has been closed.

Content reproduced on this site is the property of the respective copyright holders. It is not reviewed in advance by Oracle and does not necessarily represent the opinion of Oracle or any other party.