Yep, just put the connect function outside your recursive loop. You can then access the connection that is returned by the connect function by making it global, or passing it by reference by the recursive function.

In other words:

$connection = mysql_connect(....);
mysql_select_db($database, $connection);


function recursive_function($value)
global $connection;

$data = mysql_query($sql, $connection);



... or something.. you get the picture.


On 03/01/2007 08:52 PM, Ron Croonenberg wrote:
Hello all,

I wrote an app in php and it uses recursion.

Problem I have is that when I connect to a database using
mysql_connect($dbhost, $username, $password); and select a table with
mysql_select_db($database) I cannot access the table anymore from some

Now I can connect and select a database in that php function  but that
means that process happens A LOT and connecting and selecting everytime
probably slows down the app quite a bit

Is there a way to connect to a database and select a table "globally"
so that I have access to it in ever php function I write ?



PHP Database Mailing List (
To unsubscribe, visit:

Reply via email to