Hello, wonder if anyone can debug this script.

I copied it from an example in a book.

There is a .php file and a .inc file

This is the .inc file:

<?php
//common_db.inc
$dbhost = 'localhost';
$dbusername = 'root';
$dbuserpassword = '';
$default_dbname = 'mysql';
$MYSQL_ERRNO = '';
$MYSQL_ERROR = '';
function db_connect($dbname="") {
global $dbhost, $dbusername, $dbuserpassword, $default_dbname, $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 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";
}
?>


the .php file is like this:

<?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>";
}
?>

Sorry about poxy formatting, hope it is legible.

I seem to have a problem passing the database to the db_connect() function
within the .php script.
The $default_dbname variable within the .inc file is always selected instead
of the argument I pass.

Anyone help me please?

Ta.



-- 
PHP Database 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]

Reply via email to