Bluehost.com Web Hosting $6.95

require_once() driving me MAD ! - please HELP

This is a discussion on require_once() driving me MAD ! - please HELP within the PHP Language forums, part of the PHP Programming Forums category; I have written a number of PHP include files. I have carefully partitioned them into logical folders - based on functionality. ...


Go Back   Usenet Forums > PHP Programming Forums > PHP Language

FAQ Members List Calendar Search Today's Posts Mark Forums Read
  #1 (permalink)  
Old 09-28-2006
Bit Byte
 
Posts: n/a
Default require_once() driving me MAD ! - please HELP

I have written a number of PHP include files. I have carefully
partitioned them into logical folders - based on functionality. My
directory structure looks something like this:

$(rootdir)/includes/
$(rootdir)/includes/patterns
$(rootdir)/includes/core/db
$(rootdir)/includes/core/utils
$(rootdir)/includes/core/logger
....

etc.

Each folder contains one or more files. I wrote the following script to
test my db classes:

<?php
echo "In script\n" ;
include ("/db/mysql_database.inc.php");
echo "Got here\n" ;

try
{
echo "Attempting to instantiate db object\n" ;
$m_dbconnection = new MySQLDatabase();
echo "Object created succesfully\n" ;
}
catch (Exception $e)
{
echo "Exception caught : " . $e->getMessage() . "\n" ;
}
?>

Output: "In script Got here Attempting to instantiate db object "

I cannot, for the life of me, work out wtf is wrong iwth the script, and
why I can't seem to use my directory structure. The above script is
being run from $(rootdir). $(rootdir) is in folder htdocs under Apache.

Additional Info:
----------------------
PHP Version: PHP5
Web Server: Apache 2.0
OS: Windows 2K



Reply With Quote
  #2 (permalink)  
Old 09-28-2006
Jerry Stuckle
 
Posts: n/a
Default Re: require_once() driving me MAD ! - please HELP

Bit Byte wrote:
> I have written a number of PHP include files. I have carefully
> partitioned them into logical folders - based on functionality. My
> directory structure looks something like this:
>
> $(rootdir)/includes/
> $(rootdir)/includes/patterns
> $(rootdir)/includes/core/db
> $(rootdir)/includes/core/utils
> $(rootdir)/includes/core/logger
> ...
>
> etc.
>
> Each folder contains one or more files. I wrote the following script to
> test my db classes:
>
> <?php
> echo "In script\n" ;
> include ("/db/mysql_database.inc.php");
> echo "Got here\n" ;
>
> try
> {
> echo "Attempting to instantiate db object\n" ;
> $m_dbconnection = new MySQLDatabase();
> echo "Object created succesfully\n" ;
> }
> catch (Exception $e)
> {
> echo "Exception caught : " . $e->getMessage() . "\n" ;
> }
> ?>
>
> Output: "In script Got here Attempting to instantiate db object "
>
> I cannot, for the life of me, work out wtf is wrong iwth the script, and
> why I can't seem to use my directory structure. The above script is
> being run from $(rootdir). $(rootdir) is in folder htdocs under Apache.
>
> Additional Info:
> ----------------------
> PHP Version: PHP5
> Web Server: Apache 2.0
> OS: Windows 2K
>
>
>


include ("/db/mysql_database.inc.php");

This would be an absolute path to the file system, not a relative path
in your web server. If you were displaying errors you would have one
indicating the file was not found.

--
==================
Remove the "x" from my email address
Jerry Stuckle
JDS Computer Training Corp.
jstucklex@attglobal.net
==================
Reply With Quote
  #3 (permalink)  
Old 09-28-2006
Bit Byte
 
Posts: n/a
Default Re: require_once() driving me MAD ! - please HELP



Jerry Stuckle wrote:

> Bit Byte wrote:
>
>> I have written a number of PHP include files. I have carefully
>> partitioned them into logical folders - based on functionality. My
>> directory structure looks something like this:
>>
>> $(rootdir)/includes/
>> $(rootdir)/includes/patterns
>> $(rootdir)/includes/core/db
>> $(rootdir)/includes/core/utils
>> $(rootdir)/includes/core/logger
>> ...
>>
>> etc.
>>
>> Each folder contains one or more files. I wrote the following script
>> to test my db classes:
>>
>> <?php
>> echo "In script\n" ;
>> include ("/db/mysql_database.inc.php");
>> echo "Got here\n" ;
>>
>> try
>> {
>> echo "Attempting to instantiate db object\n" ;
>> $m_dbconnection = new MySQLDatabase();
>> echo "Object created succesfully\n" ;
>> }
>> catch (Exception $e)
>> {
>> echo "Exception caught : " . $e->getMessage() . "\n" ;
>> }
>> ?>
>>
>> Output: "In script Got here Attempting to instantiate db object "
>>
>> I cannot, for the life of me, work out wtf is wrong iwth the script,
>> and why I can't seem to use my directory structure. The above script
>> is being run from $(rootdir). $(rootdir) is in folder htdocs under
>> Apache.
>>
>> Additional Info:
>> ----------------------
>> PHP Version: PHP5
>> Web Server: Apache 2.0
>> OS: Windows 2K
>>
>>
>>

>
> include ("/db/mysql_database.inc.php");
>
> This would be an absolute path to the file system, not a relative path
> in your web server. If you were displaying errors you would have one
> indicating the file was not found.
>


Hi Jerry, not sure I follow your response (i.e. its rather ambigious).
Did you mean to say that my include directive SHOULD (you wrote WOULD)
be an absolute path to the file system ?.

To avoid going round in circles over the syntax of should and would,
could you please correct the include statement - so that the new line is
the correct statement that will work.

For example, should I write:

include ("c:\my_full_path\db\mysql_database.inc.php"); //note windows
path notation OR
include ("c:/my_full_path/db/mysql_database.inc.php"); OR
include
("../path_relative_from_THIS_file_to_include_file/db/mysql_database.inc.php");
OR
include
("..\path_relative_from_THIS_file_to_include_file\ db\mysql_database.inc.php")

?

Reply With Quote
  #4 (permalink)  
Old 09-28-2006
Mateusz Markowski
 
Posts: n/a
Default Re: require_once() driving me MAD ! - please HELP

Bit Byte napisal(a):
> I have written a number of PHP include files. I have carefully
> partitioned them into logical folders - based on functionality. My
> directory structure looks something like this:
>
> $(rootdir)/includes/
> $(rootdir)/includes/patterns
> $(rootdir)/includes/core/db
> $(rootdir)/includes/core/utils
> $(rootdir)/includes/core/logger
> ...
>
> etc.
>
> Each folder contains one or more files. I wrote the following script to
> test my db classes:
>
> <?php
> echo "In script\n" ;
> include ("/db/mysql_database.inc.php");
> echo "Got here\n" ;
>
> try
> {
> echo "Attempting to instantiate db object\n" ;
> $m_dbconnection = new MySQLDatabase();
> echo "Object created succesfully\n" ;
> }
> catch (Exception $e)
> {
> echo "Exception caught : " . $e->getMessage() . "\n" ;
> }
> ?>
>
> Output: "In script Got here Attempting to instantiate db object "
>
> I cannot, for the life of me, work out wtf is wrong iwth the script, and
> why I can't seem to use my directory structure. The above script is
> being run from $(rootdir). $(rootdir) is in folder htdocs under Apache.


Why do you think it's a directory structure problem? You wrote that in
the ouput you get only "In script Got here Attempting to instantiate db
object ", so it stops in MySQLDatabase. Maybe there is an error.

Reply With Quote
  #5 (permalink)  
Old 09-28-2006
Jerry Stuckle
 
Posts: n/a
Default Re: require_once() driving me MAD ! - please HELP

Bit Byte wrote:
>
>
> Jerry Stuckle wrote:
>
>> Bit Byte wrote:
>>
>>> I have written a number of PHP include files. I have carefully
>>> partitioned them into logical folders - based on functionality. My
>>> directory structure looks something like this:
>>>
>>> $(rootdir)/includes/
>>> $(rootdir)/includes/patterns
>>> $(rootdir)/includes/core/db
>>> $(rootdir)/includes/core/utils
>>> $(rootdir)/includes/core/logger
>>> ...
>>>
>>> etc.
>>>
>>> Each folder contains one or more files. I wrote the following script
>>> to test my db classes:
>>>
>>> <?php
>>> echo "In script\n" ;
>>> include ("/db/mysql_database.inc.php");
>>> echo "Got here\n" ;
>>>
>>> try
>>> {
>>> echo "Attempting to instantiate db object\n" ;
>>> $m_dbconnection = new MySQLDatabase();
>>> echo "Object created succesfully\n" ;
>>> }
>>> catch (Exception $e)
>>> {
>>> echo "Exception caught : " . $e->getMessage() . "\n" ;
>>> }
>>> ?>
>>>
>>> Output: "In script Got here Attempting to instantiate db object "
>>>
>>> I cannot, for the life of me, work out wtf is wrong iwth the script,
>>> and why I can't seem to use my directory structure. The above script
>>> is being run from $(rootdir). $(rootdir) is in folder htdocs under
>>> Apache.
>>>
>>> Additional Info:
>>> ----------------------
>>> PHP Version: PHP5
>>> Web Server: Apache 2.0
>>> OS: Windows 2K
>>>
>>>
>>>

>>
>> include ("/db/mysql_database.inc.php");
>>
>> This would be an absolute path to the file system, not a relative path
>> in your web server. If you were displaying errors you would have one
>> indicating the file was not found.
>>

>
> Hi Jerry, not sure I follow your response (i.e. its rather ambigious).
> Did you mean to say that my include directive SHOULD (you wrote WOULD)
> be an absolute path to the file system ?.
>


The one you gave is an absolute path to the file system. Do you
actually have a /db directory on your file system?

> To avoid going round in circles over the syntax of should and would,
> could you please correct the include statement - so that the new line is
> the correct statement that will work.
>


If /db is relative to your document root, the following works with any
server - Windows or Linux:

include ($_SERVER['DOCUMENT_ROOT'] . '/db/mysql_database.inc.php');

$_SERVER['DOCUMENT_ROOT'] gives the absolute path to your web site on
either system.

> For example, should I write:
>
> include ("c:\my_full_path\db\mysql_database.inc.php"); //note windows
> path notation OR
> include ("c:/my_full_path/db/mysql_database.inc.php"); OR
> include
> ("../path_relative_from_THIS_file_to_include_file/db/mysql_database.inc.php");
> OR
> include
> ("..\path_relative_from_THIS_file_to_include_file\ db\mysql_database.inc.php")
>
>
> ?
>



--
==================
Remove the "x" from my email address
Jerry Stuckle
JDS Computer Training Corp.
jstucklex@attglobal.net
==================
Reply With Quote
  #6 (permalink)  
Old 09-28-2006
ZeldorBlat
 
Posts: n/a
Default Re: require_once() driving me MAD ! - please HELP


Bit Byte wrote:
> I have written a number of PHP include files. I have carefully
> partitioned them into logical folders - based on functionality. My
> directory structure looks something like this:
>
> $(rootdir)/includes/
> $(rootdir)/includes/patterns
> $(rootdir)/includes/core/db
> $(rootdir)/includes/core/utils
> $(rootdir)/includes/core/logger
> ...
>
> etc.
>
> Each folder contains one or more files. I wrote the following script to
> test my db classes:
>
> <?php
> echo "In script\n" ;
> include ("/db/mysql_database.inc.php");
> echo "Got here\n" ;
>
> try
> {
> echo "Attempting to instantiate db object\n" ;
> $m_dbconnection = new MySQLDatabase();
> echo "Object created succesfully\n" ;
> }
> catch (Exception $e)
> {
> echo "Exception caught : " . $e->getMessage() . "\n" ;
> }
> ?>
>
> Output: "In script Got here Attempting to instantiate db object "
>
> I cannot, for the life of me, work out wtf is wrong iwth the script, and
> why I can't seem to use my directory structure. The above script is
> being run from $(rootdir). $(rootdir) is in folder htdocs under Apache.
>
> Additional Info:
> ----------------------
> PHP Version: PHP5
> Web Server: Apache 2.0
> OS: Windows 2K


Perhaps because "/db/mysql_database.inc.php" is relative to the root of
the filesystem and not the PWD?

Reply With Quote
Reply
Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are Off
[IMG] code is Off
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On




All times are GMT +1. The time now is 12:27 PM.


Powered by vBulletin® Version 3.7.3
Copyright ©2000 - 2008, Jelsoft Enterprises Ltd.
Content Relevant URLs by vBSEO 3.0.0