Forum Moderators: coopster
function db_connect($dbname='') {
global $dbhost, $dbusername, $dbuserpassword, $default_dbname;
global $MYSQL_ERRNO, $MYSQL_ERROR;
$link_id = mysql_connect($dbhost, $dbusername, $dbuserpassword);
if(!$link_id) {
$MYSQL_ERRNO = 0;
$MYSQL_ERROR = 'Connection failed to the host ' .$dbhost;
return 0;
}
else if(empty($dbname) && !mysql_select_db($default_dbname)) {
$MYSQL_ERRNO = mysql_errno();
$MYSQL_ERROR = mysql_error();
return 0;
}
else if(!empty($dbname) && !mysql_select_db($dbname)) {
$MYSQL_ERRNO = mysql_errno();
$MYSQL_ERROR = mysql_error();
return 0;
}
else return $link_id;
}
if nothing is passed then it will use whatever is set in the declaration.
this syntax can only be used on the last param, if i remember correctly. So if you had more than one param
this would be correct
function db_connect($dbpass, $dbname='') {
where this is not correct
function db_connect($dbpass='', $dbname) {
<added>
[php.net...]
my memory was not fully exact
Note that when using default arguments, any defaults should be on the right side of any non-default arguments; otherwise, things will not work as expected.