For Programmers: Free Programming Magazines  


Home > Archive > PHP DB > March 2007 > Re: [PHP-DB] problems with functions/included files/mysql resource









You are viewing an archived Text-only version of the thread. To view this thread in it's original format and/or if you want to reply to this thread please [click here]

 

Author Re: [PHP-DB] problems with functions/included files/mysql resource
Niel Archer

2007-03-28, 3:58 am

Hi,
>
> In the function to connect to and select the database, I make the mysql-link
> resource a global value.


It sounds like you've misunderstood 'global' variable. The global
statement needs to go inside the function where you want to use the
variable, not where you assign it. This tells that function to access
that variable from the global scope. You will need to have this
variable available at the global scope. Creating it inside another
function will not do, you must return that from the function to the
global scope too

e.g.

<?php

$db = new mysql;

... some code ...


function UseDb()
{
global $db;

... some more code ...
}

?>

Niel
Sponsored Links







Also available: Server administration forum archive | Web Design forum archive | Software forum archive | Hardware reviews archive

Copyright 2008 codecomments.com