I use the same MySQL username as my database name so I use the same variable $name for both of them and append it with a prefix (ex. mysite_blog, mysite_forum). My problem seems to be getting the variables into the functions - which is my weak point. Here is my code:
Code: Select all
<?php
$host = "localhost";
$name = "PREFIXHERE";
$pass = "PASSWORDHERE";
function db_main () {$name .= 'main'; db_connect();}
function db_blog () {$name .= 'blog'; db_connect();}
function db_gallery() {$name .= 'gallery'; db_connect();}
function db_forum () {$name .= 'forum'; db_connect();}
function db_webmail() {$name .= 'webmail'; db_connect();}
function db_connect($host, $name, $pass) {
mysql_connect($host, $name, $pass) or die(mysql_error());
mysql_select_db($user) or die(mysql_error());
}
Code: Select all
Warning: Missing argument 1 for db_gallery(), called in /htdocs/www/index.php on line 57 and defined in /htdocs/PHP/includes/config.inc on line 16
Warning: mysql_query() [function.mysql-query]: Can't connect to local MySQL server through socket '/tmp/mysql.sock' (2) in /htdocs/www/index.php on line 58
Warning: mysql_query() [function.mysql-query]: A link to the server could not be established in /htdocs/www/index.php on line 58
Can't connect to local MySQL server through socket '/tmp/mysql.sock' (2)