Re: recursion in php and mysql

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



It will complain if your query isn't returning any results. Check for that too.

-Micah

On 03/01/2007 09:36 PM, Ron Croonenberg wrote:
Hi Micah,

thanks I have a bunch of things working now.

mysql_fetch_array() is complaining.

I use it like this:

function recursive() {
global $connection;

$result = mysql_query("SELECT * FROM $table WHERE bthb4='$bthb4'", $connection);
$row = mysql_fetch_array($result);
}

the error I got was:
Warning: mysql_fetch_array(): supplied argument is not a valid MySQL result resource in recursion.php on line 93

I tried: $row = mysql_fetch_array($result, $connection);

But I have the impression that $result  now isn't correct anymore ?

the mysql_fetch_array() is the only function (so far) that complains ?

thanks for your earlier very quick response,

Ron


Micah Stevens <micah@xxxxxxxxxxxxxxxxxx> 03/02/07 12:04 AM >>>
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);

recursive_function($value);

function recursive_function($value)
{
global $connection;

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

recursive_function($data);

}

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

-Micah



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
function.

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 ?

thanks,

Ron



[Index of Archives]     [PHP Home]     [PHP Users]     [Postgresql Discussion]     [Kernel Newbies]     [Postgresql]     [Yosemite News]

  Powered by Linux