Hello,
Wonder if anyone can help me out.
I am trying to run an example out of a book Beginning Php by wrox.
One of the examples is supposed to allow me to connect to a database by
using a function that takes a database as an argument. It has an include
file that contains the function.
Problem I get is that the argument never seems to get passed and the
function always uses the default value.
I would greatly appreciate if someone could tell me why this happens. I
would also appreciate if no one rewrites a completely different script, as I
am after debugging this one. ;-)
Here is the include file:
?php
//common_db.inc
$dbhost = 'localhost';
$dbusername = 'phpuser';
$dbuserpassword = 'phppass';
$default_dbname = 'mysql';
$MYSQL_ERRNO = '';
$MYSQL_ERROR = '';
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;
}
function sql_error() {
global $MYSQL_ERRNO, $MYSQL_ERROR;
if(empty($MYSQL_ERROR)) {
$MYSQL_ERRNO = mysql_errno();
$MYSQL_ERROR = mysql_error();
}
return $MYSQL_ERRNO: $MYSQL_ERROR;
}
?
And here is the php script that uses this include file:
?php
//show_more_db.php
include ./common_db.inc;
$link_id = db_connect('sample_db');
$result = mysql_query(SELECT * FROM user, $link_id);
while($query_data = mysql_fetch_row($result)) {
?
?php
echo ',$query_data[1],' is also php ' known as ,$query_data[3],P;
}
?
I hope someone can help me out please.
Thankyou.
--
PHP General Mailing List (http://www.php.net/)
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]
To contact the list administrators, e-mail: [EMAIL PROTECTED]