note 79999 added to function.mysql-connect
| From: | mathewcausby at hotmail dot com | Date: | Sun, 23 Dec 2007 12:45:44 +0000 |
| Subject: | note 79999 added to function.mysql-connect | ||
| Groups: | php.notes | ||
| Request: | Send a blank email to php-notes+get-133898@lists.php.net to get a copy of this message | ||
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
----
Server IP: 69.147.83.197
Probable Submitter: 124.178.171.167
----
Manual Page -- http://www.php.net/manual/en/function.mysql-connect.php
Edit -- https://master.php.net/note/edit/79999
Del: integrated -- https://master.php.net/note/delete/79999/integrated
Del: useless -- https://master.php.net/note/delete/79999/useless
Del: bad code -- https://master.php.net/note/delete/79999/bad+code
Del: spam -- https://master.php.net/note/delete/79999/spam
Del: non-english -- https://master.php.net/note/delete/79999/non-english
Del: in docs -- https://master.php.net/note/delete/79999/in+docs
Del: other reasons-- https://master.php.net/note/delete/79999
Reject -- https://master.php.net/note/reject/79999
Search -- https://master.php.net/manage/user-notes.php