well, I didn't debug this massive script, but
maybe you just want to connect to a mysql database?
then this is the short way:

$user = "your_username_for_the_database";
$pass = "your_password_for_the_database";

$con = mysql_connect("your_host", $user, $pass);

if(!$con) {
    print "no connection";
}

I really don't know if this is what you're asking for....

Leo Kuiper

"Building a map in order to find what's not lost but left behind."
 - Beth Orton


----- Original Message -----
From: Ian <[EMAIL PROTECTED]>
To: <[EMAIL PROTECTED]>
Sent: Wednesday, November 28, 2001 5:52 PM
Subject: [PHP-DB] db connect problems.


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


-- 
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