Inside your function define:
global $server;
global $pass;
global $user;
etc....
It is using variables insides it's own scope and unless you have use
GLOBAL_VARIABLES defined in your php.config file, it won't go outside of it's
scope to look for values, hence they are getting asigned NULL and you can't
connect to a NULL DB :)
Henrik
On Sunday 28 October 2001 14:57, jtjohnston wrote:
> Sigh ...
>
> I have "functions.inc" in which I have Table_Title().
>
> As soon as I put my database connection inside my function called
> Table_Title(), my database connection fails. (See second example below.)
>
> My database connection works fine whenever IT IS NOT inside "function
> Table_Title()". (See first example below.)
>
> It seems that when I try to connect to my database inside "function
> Table_Title()", my function cannot read the values of $server, $user,
> $pass, "$db or $table ???
>
> I call it normally??
>
> <?php Table_Title() ?>
>
> Can anyone help??
>
>
> --------------SNIP THIS WORKS FINE! --------------------
> <?php
>
> $server = "localhost";
> $user = "MyAccount";
> $pass = "MyPassword";
> $db = "MyDatabase";
> $table = "bookmark_unit4";
>
> $myconnection = mysql_pconnect($server,$user,$pass);
> mysql_select_db($db,$myconnection);
> $news = mysql_query("SHOW TABLE STATUS FROM ".$db." LIKE '$table'");
> while ($news_story = mysql_fetch_array($news))
> {
> $table_comment = $news_story['Comment'];
> }
> echo $table_comment;
>
> function Table_Title()
> {
> echo "Nothing";
> }
> ?>
>
> -------------- SNIP THIS DOES NOT WORK --------------------
> <?php
>
> $server = "localhost";
> $user = "MyAccount";
> $pass = "MyPassword";
> $db = "MyDatabase";
> $table = "bookmark_unit4";
>
> function Table_Title()
> {
> $myconnection = mysql_pconnect($server,$user,$pass);
> mysql_select_db($db,$myconnection);
>
> $news = mysql_query("SHOW TABLE STATUS FROM ".$db." LIKE '$table'");
> while ($news_story = mysql_fetch_array($news))
> {
> $table_comment = $news_story['Comment'];
> }
>
> echo $table_comment;
> //echo "Nothing";
> }
> ?>
--
Henrik Hudson
[EMAIL PROTECTED]
--
PHP General 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]