You are here: Re: Functions in Include Files « All PHP « IT news, forums, messages
Re: Functions in Include Files

Posted by PSI_Orion on 07/28/06 17:58

I presume you can have the file anywhere as long as you reference the file
by the full path. in other words, I can keep it in the root path rather than
in the includes path? I do a result check (with the code you supplied) and
I do get a result of 1 for the include, it's just that it can't see the
function when it calls it for some unknown reason.

Thanks for the help.

"J.O. Aho" <user@example.net> wrote in message
news:4iuvn1F5ikhfU1@individual.net...
> PSI_Orion wrote:
>> Is it possible to have functions in include files? I am trying to
>> generate a global function include for opening my databases but it comes
>> back and says:
>>
>> Fatal error: Call to undefined function dbaseConnect() in
>> D:\Inetpub\wwwroot\psiss.com\dummy\index.php on line 19
>>
>> The include file is this...
>>
>> <?
>> if(!(include 'XXXXXXXXX'))
>> die("<p align='center'><font color='#FF0000'><b>FAILED TO INCLUDE
>> 'XXXXXXXXX'</b></font></p>");
>>
>> function dbaseConnect($dbaseName,$tableName)
>> {
>> $dbase=@mysql_connect($dbaseName,$dbaseUser,$dbasePW);
>> if(!$dbase)
>> die("<p align='center'><font color='#FF0000'><b>ERROR CONNECTING TO
>> MySQL SERVER</b></font></p>");
>> $tables=@mysql_list_tables($tableName,$dbase);
>> if(!$tables)
>> die("<p align='center'><font color='#FF0000'><b>ERROR RETRIEVING TABLES
>> FROM DATABASE '".$dbaseName."'</b></font></p>");
>> $FOUND=false;
>> for($i = 0; $i < @mysql_num_rows($tables) && (!$FOUND); $i++)
>> {
>> if(@mysql_tablename($tables,$i) == $tableName)
>> $FOUND=true;
>> }
>> if(!$FOUND)
>> die("<p align='center'><font color='#FF0000'><b>ERROR RETRIEVING TABLE
>> '".$tableName."'</b></font></p>");
>> }
>> ?>
>>
>> and the include stuff in the main file is this which is declared before
>> the dbaseConnect() call.
>>
>> if(!(include 'XXXXXXXXXXX'))
>> die("<p align='center'><font color='#FF0000'><b>FAILED TO INCLUDE
>> 'XXXXXXX'</b></font></p>");
>> dbaseConnect("xxxxxxx","xxxxxxx");
>>
>> Obviously, for security reasons, I've changed the file names in this code
>> to XXXXXXXXXX.
>>
>
>
> --- index.php ---
> include_once("database.php");
> $tableName="YYYYYY";
> if(!dbaseConnect("xxxxxxx",$tableName))
> die("<p align='center'><font color='#FF0000'><b>ERROR RETRIEVING TABLE
> '".$tableName."'</b></font></p>");
> --- eof ---
>
> --- database.php ---
> <?PHP
> function
> dbaseConnect($dbServer,$dbaseName,$tableName,$dbaseUser="user",$dbasePW="pass")
> {
> if(!$link=@mysql_connect($dbServer,$dbaseUser,$dbasePW))
> die("<p align='center'><font color='#FF0000'><b>ERROR CONNECTING TO
> MySQL SERVER</b></font></p>");
> if(!mysql_select_db($databaseName, $link))
> die("<p align='center'><font color='#FF0000'><b>ERROR ACCESSING
> DATABASE '".$dbaseName."'</b></font></p>");
> if(!$tables=@mysql_list_tables($tableName,$link))
> die("<p align='center'><font color='#FF0000'><b>ERROR RETRIEVING
> TABLES FROM DATABASE '".$dbaseName."'</b></font></p>");
> while($name=mysql_fetch_row($tables)) {
> if($name[0]==$tableName)
> return true;
> }
> return false;
> }
> > ?>
> --- eof ---
>
> This should work fine.

 

Navigation:

[Reply to this message]


Удаленная работа для программистов  •  Как заработать на Google AdSense  •  England, UK  •  статьи на английском  •  PHP MySQL CMS Apache Oscommerce  •  Online Business Knowledge Base  •  DVD MP3 AVI MP4 players codecs conversion help
Home  •  Search  •  Site Map  •  Set as Homepage  •  Add to Favourites

Copyright © 2005-2006 Powered by Custom PHP Programming

Сайт изготовлен в Студии Валентина Петручека
изготовление и поддержка веб-сайтов, разработка программного обеспечения, поисковая оптимизация