note 79999 deleted from function.mysql-connect by nlopess
| From: | nlopess@php.net | Date: | Sun, 23 Dec 2007 12:59:31 +0000 |
| Subject: | note 79999 deleted from function.mysql-connect by nlopess | ||
| References: | 1 | Groups: | php.notes |
| Request: | Send a blank email to php-notes+get-133899@lists.php.net to get a copy of this message | ||
Note Submitter: mathewcausby at hotmail dot com
----
I'm not sure if this has been stuck on before but this is something I like to do.
Say if most of your pages need to connect to a MySQL server, and you change server.
It's a big hassle to go through every page and change the connection settings.
That is why I created the following function inside an external file.
That way you just need to change the information there.
The MySQL Connection Information is the same as if you are running it on your localhost using WAMP.
The basic information.
<?php
function mysql_data($a){
if($a == 'host'){
return 'localhost';
}
if($a == 'user'){
return 'root';
}
if($a == 'pass'){
return '';
}
}
?>
Now on the page when you connect you simply have to write,
<?php
if(!$link = @mysql_connect(mysql_data('host'),mysql_data('user'),
mysql_data('pass'))){
echo "<p>Could not connect to MySQL: ".mysql_error()."</p>";
die();
}
?>
I hope this is usefull to anyone XD