beginning_php thread: Re: Working Offline to test PHP scripts, How to! AND NEW QUESTION ABOUT INCLUDE FILE ON PAGE 413

 Message #1 by "Tan Le" on Mon, 23 Jul 2001 03:48:56 -0500
When running without the Internet connection, IE5 will ask to "Work

Offline" and "Try Again".  This time I selected "Try Again" and it

forces the server to use the http://127.0.0.1 or http://hummingbird.

Simple solution!

New question: I am on page 413 where it shows the database connection

script as below.  Please explain where and how do I configure the

include file???  The PHP script (saved as createdbphp.php) has the

following statements:

<?php

//create_db.php

include "./common_db.inc";       //line 3

$dbname="sample_db";$user_tablename="user";

$user_table_def="usernumber mediumint(10) default '0' not null auto_increment,";$user_table_def.="userid varchar(8) binary not null,";

$user_table_def.="userpassword varchar(20) binary not null,";$user_table_def.="username varchar(30) not null,";

$user_table_def.="usercountry varchar(50) not null,";$user_table_def.="useremail varchar(50) not null,";

$user_table_def.="userprofile text not null,";$user_table_def.="registerdate date default '0000-00-00' not null,";

$user_table_def.="lastaccesstime timestamp(14),";$user_table_def.="primary key (userid),";

$user_table_def.="unique usernumber (usernumber)";$access_log_tablename="access_log";

$access_log_table_def="page varchar(250) not null,";$access_log_table_def.="userid varchar(8) binary not null,";

$access_log_table_def.="visitcount mediumint(5) default'0' not null,";$access_log_table_def.="accessdate timestamp(14),";

$access_log_table_def.="primary key (userid, page)";$link_id=db_connect();

if(!$link_id) die(sql_error()); //line 26 if(!mysql_query("create database$dbname")) die(sql_error());

echo "Successfully created the $dbname database.<BR>"; if(!mysql_select_db($dbname)) die(sql_error());

if(!mysql_query("create table $user_tablename ($user_table_def)"))

die(sql_error());

if(!mysql_query("create table $access_log_tablename ($access_log_table_def)")) die(sql_error());

echo "Succcessfully created the $user_tablename and$access_log_tablename tables.";

?>

-------

When I execute the file, an error came up as:

Warning: Failed opening './common_db.inc' for inclusion

(include_path='') in c:\inetpub\wwwroot\createdbphp.php on line 3

Fatal error: Call to undefined function: db_connect() in

c:\inetpub\wwwroot\createdbphp.php on line 26

-------

To explain: line 3 is the above statement of:   include

"./common_db.inc";

And line 26 is: if(!$link_id) die(sql_error));   Message #2 by Jesse Goerz on Mon, 23 Jul 2001 07:23:13 -0500 On Monday 23 July 2001 03:48, Tan Le wrote: > When running without the Internet connection, IE5 will ask to "Work > Offline" and "Try Again". This time I selected "Try Again" and it > forces the server to use the http://127.0.0.1 or http://hummingbird. > Simple solution! Amazing, even though we get flamed by some condescending lame-o, it's the simple hosts file which is the solution as mentioned in previous posts. Good job Tan!;-) > New question: I am on page 413 where it shows the database connection > script as below. Please explain where and how do I configure the > include file??? The PHP script (saved as createdbphp.php) has the > following statements: > > <?php > //create_db.php > include "./common_db.inc"; //line 3 The file common_db.inc is an include file which, based on it's name probably has a bunch of common variables or functions related to database use. Here, you're telling it to look in the current working directory to find the file. Read on to find out more. [...] >$link_id=db_connect();

> if(!$link_id) die(sql_error()); //line 26 > if(!mysql_query("create database$dbname")) die(sql_error());

> echo "Successfully created the $dbname database.<BR>"; > > if(!mysql_select_db($dbname)) die(sql_error());

> if(!mysql_query("create table $user_tablename ($user_table_def)"))

> die(sql_error());

> if(!mysql_query("create table $access_log_tablename > ($access_log_table_def)")) die(sql_error());

>

> echo "Succcessfully created the $user_tablename and >$access_log_tablename tables.";

>

> ?>

>

> -------

> When I execute the file, an error came up as:

>

> Warning: Failed opening './common_db.inc' for inclusion

> (include_path='') in c:\inetpub\wwwroot\createdbphp.php on line 3

This part of the error is telling you that the file common_db.inc is not in

you're current path and is not where you told php it was supposed to be.  As

a side note, whenever you type "./" before a filename you're telling php to

look in the current directory for that file.  Use the find files option of

windows and search for common_db.inc.  If it's not on your computer check the

cdrom that came with the book.  Make sure you copy the file into the

directory you're telling php it's in.  In this case that appears to be:

c:\inetpub\wwwroot\

Or just simply change the path for common_db.inc to match where you found it.

(i.e. c:\directory\where\it\is\common_db.inc)  It's probably best to do this

only if the path is a subdirectory of c:\inetpub\wwwroot\.

> Fatal error: Call to undefined function: db_connect() in

> c:\inetpub\wwwroot\createdbphp.php on line 26

I'm assuming that db_connect() is one of the functions which is a part of

common_db.inc.  Because common_db.inc didn't get included properly, the

function is undefined (the computer doesn't know what it's supposed to do) so

it gives you this warning.  If you can get common_db.inc copied into your

local directory and db_connect() is defined in that include file this error

will go away.

> -------

> To explain: line 3 is the above statement of:   include

> "./common_db.inc";

> And line 26 is: if(!$link_id) die(sql_error)); Line 26 is doing exactly what it's supposed to. It's error handling code. Because$link_id turned up false or "not true" the if condition was met and

the die() function is called with the sql_error() parameter which is why you

got the error referencing line 26.

HTH,

Jesse


 Message #3 by "Tan Le" on Mon, 23 Jul 2001 10:14:12 -0500
Thanks very much Jessie for your excellent comment.  I'd greatly

appreciate your detailed regards.  It's hard to find people like you who

tells explicit explanation to every problem.  I did a search and found

no sight of the file common_db.inc.  The book didn't have a CD.  The

back of the book does not have a CD sleeve so I don't think it was sold

with a CD.  Where can I find that file and attach it to

c:\inetpub\wwwroot?  The server p2p.wrox.com was down last night so I

couldn't find it.  Please instruct me a site that I can download.

Sincerely,

Tan Le

-----Original Message-----

From: Jesse Goerz [mailto:jgoerz@l...]

Sent: Monday, July 23, 2001 7:23 AM

To: beginning php

Subject: [beginning_php] Re: Working Offline to test PHP scripts, How

to! AND NEW QUESTION ABOUT INCLUDE FILE ON PAGE 413

On Monday 23 July 2001 03:48, Tan Le wrote:

> When running without the Internet connection, IE5 will ask to "Work

> Offline" and "Try Again".  This time I selected "Try Again" and it

> forces the server to use the http://127.0.0.1 or http://hummingbird.

> Simple solution!

Amazing, even though we get flamed by some condescending lame-o, it's

the

simple hosts file which is the solution as mentioned in previous posts.

Good

job Tan!;-)

> New question: I am on page 413 where it shows the database connection

> script as below.  Please explain where and how do I configure the

> include file???  The PHP script (saved as createdbphp.php) has the

> following statements:

>

> <?php

> //create_db.php

> include "./common_db.inc";       //line 3

The file common_db.inc is an include file which, based on it's name

probably

has a bunch of common variables or functions related to database use.

Here,

you're telling it to look in the current working directory to find the

file.

Read on to find out more.

[...]

> $link_id=db_connect(); > if(!$link_id) die(sql_error());                 //line 26

> if(!mysql_query("create database $dbname")) die(sql_error()); echo > "Successfully created the$dbname database.<BR>";

>

> if(!mysql_select_db($dbname)) die(sql_error()); > if(!mysql_query("create table$user_tablename ($user_table_def)")) > die(sql_error()); if(!mysql_query("create table$access_log_tablename

> ($access_log_table_def)")) die(sql_error()); > > echo "Succcessfully created the$user_tablename and

> $access_log_tablename tables."; > > ?> > > ------- > When I execute the file, an error came up as: > > Warning: Failed opening './common_db.inc' for inclusion > (include_path='') in c:\inetpub\wwwroot\createdbphp.php on line 3 This part of the error is telling you that the file common_db.inc is not in you're current path and is not where you told php it was supposed to be. As a side note, whenever you type "./" before a filename you're telling php to look in the current directory for that file. Use the find files option of windows and search for common_db.inc. If it's not on your computer check the cdrom that came with the book. Make sure you copy the file into the directory you're telling php it's in. In this case that appears to be: c:\inetpub\wwwroot\ Or just simply change the path for common_db.inc to match where you found it. (i.e. c:\directory\where\it\is\common_db.inc) It's probably best to do this only if the path is a subdirectory of c:\inetpub\wwwroot\. > Fatal error: Call to undefined function: db_connect() in > c:\inetpub\wwwroot\createdbphp.php on line 26 I'm assuming that db_connect() is one of the functions which is a part of common_db.inc. Because common_db.inc didn't get included properly, the function is undefined (the computer doesn't know what it's supposed to do) so it gives you this warning. If you can get common_db.inc copied into your local directory and db_connect() is defined in that include file this error will go away. > ------- > To explain: line 3 is the above statement of: include > "./common_db.inc"; > And line 26 is: if(!$link_id) die(sql_error));

Line 26 is doing exactly what it's supposed to.  It's error handling

code.

Because \$link_id turned up false or "not true" the if condition was met

and

the die() function is called with the sql_error() parameter which is why

you

got the error referencing line 26.

HTH,

Jesse