Re: [PHP-DB] recursion in php and mysql
Hello, You can use class like the following code .:) Execute(); $query2 = new MySQLCommand ($sql2, $conn); $query2->Execute(); .. ?> "Micah Stevens" <[EMAIL PROTECTED]>, haber iletisinde sunlari yazdi:[EMAIL PROTECTED] > Classes are overrated. :) > > Bastien Koert wrote: >> you could make the connection variable global, but the best bet here >> is to use a class and create a db object that your functions could call >> >> Bastien >> >> >>> From: Ron Croonenberg <[EMAIL PROTECTED]> >>> To: php-db@lists.php.net >>> Subject: [PHP-DB] recursion in php and mysql >>> Date: Thu, 01 Mar 2007 23:52:54 -0500 >>> >>> 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 >>> >>> -- >>> PHP Database Mailing List (http://www.php.net/) >>> To unsubscribe, visit: http://www.php.net/unsub.php >>> >> >> _ >> Find out the restaurants participating in Winterlicious >> http://local.live.com/default.aspx?v=2&cp=43.658648~-79.383962&style=r&lvl=15&tilt=-90&dir=0&alt=-1000&scene=3702663&cid=7ABE80D1746919B4!1329 >> From January 26 to February 8, 2007 >> > -- PHP Database Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
Re: [PHP-DB] recursion in php and mysql
I agree there. >>> Micah Stevens <[EMAIL PROTECTED]> 03/02/07 12:46 PM >>> Classes are overrated. :) Bastien Koert wrote: > you could make the connection variable global, but the best bet here > is to use a class and create a db object that your functions could call > > Bastien > > >> From: Ron Croonenberg <[EMAIL PROTECTED]> >> To: php-db@lists.php.net >> Subject: [PHP-DB] recursion in php and mysql >> Date: Thu, 01 Mar 2007 23:52:54 -0500 >> >> 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 >> >> -- >> PHP Database Mailing List (http://www.php.net/) >> To unsubscribe, visit: http://www.php.net/unsub.php >> > > _ > Find out the restaurants participating in Winterlicious > http://local.live.com/default.aspx?v=2&cp=43.658648~-79.383962&style=r&lvl=15&tilt=-90&dir=0&alt=-1000&scene=3702663&cid=7ABE80D1746919B4!1329 > > From January 26 to February 8, 2007 > -- PHP Database Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
Re: [PHP-DB] recursion in php and mysql
Classes are overrated. :) Bastien Koert wrote: you could make the connection variable global, but the best bet here is to use a class and create a db object that your functions could call Bastien From: Ron Croonenberg <[EMAIL PROTECTED]> To: php-db@lists.php.net Subject: [PHP-DB] recursion in php and mysql Date: Thu, 01 Mar 2007 23:52:54 -0500 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 -- PHP Database Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php _ Find out the restaurants participating in Winterlicious http://local.live.com/default.aspx?v=2&cp=43.658648~-79.383962&style=r&lvl=15&tilt=-90&dir=0&alt=-1000&scene=3702663&cid=7ABE80D1746919B4!1329 From January 26 to February 8, 2007 -- PHP Database Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
Re: [PHP-DB] recursion in php and mysql
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 <[EMAIL PROTECTED]> 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
RE: [PHP-DB] recursion in php and mysql
you could make the connection variable global, but the best bet here is to use a class and create a db object that your functions could call Bastien From: Ron Croonenberg <[EMAIL PROTECTED]> To: php-db@lists.php.net Subject: [PHP-DB] recursion in php and mysql Date: Thu, 01 Mar 2007 23:52:54 -0500 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 -- PHP Database Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php _ Find out the restaurants participating in Winterlicious http://local.live.com/default.aspx?v=2&cp=43.658648~-79.383962&style=r&lvl=15&tilt=-90&dir=0&alt=-1000&scene=3702663&cid=7ABE80D1746919B4!1329 From January 26 to February 8, 2007 -- PHP Database Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
Re: [PHP-DB] recursion in php and mysql
>>$row = mysql_fetch_array($result, $connection); this is the problem you should type $row = mysql_fetch_array($result, MYSQL_NUM); there not such things as $connection on the mysql_fetch_array in mysql_query.. u use that connection.. but not in fetch array array mysql_fetch_array ( resource result [, int result_type] ) - Original Message - From: "Ron Croonenberg" <[EMAIL PROTECTED]> To: <[EMAIL PROTECTED]> Cc: Sent: Friday, March 02, 2007 12:36 PM Subject: Re: [PHP-DB] recursion in php and mysql 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 <[EMAIL PROTECTED]> 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 > > -- PHP Database Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php -- PHP Database Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php -- PHP Database Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
Re: [PHP-DB] recursion in php and mysql
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 <[EMAIL PROTECTED]> 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 > > -- PHP Database Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php -- PHP Database Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
Re: [PHP-DB] recursion in php and mysql
hmm.. i think there something going on on this func mysql_select_db($database) read more below == - Original Message - From: "Ron Croonenberg" <[EMAIL PROTECTED]> To: Sent: Friday, March 02, 2007 11:52 AM Subject: [PHP-DB] recursion in php and mysql > 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. try this mysql_select_db($database) or die(mysql_error()); = > 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 -- PHP Database Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
Re: [PHP-DB] recursion in php and mysql
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 -- PHP Database Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
[PHP-DB] recursion in php and mysql
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 -- PHP Database Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
Re: [PHP-DB] recursion
I think it might be $this->deptree ! Every time you create an object the "$" is replaced by "$this->" . HTH. Jayme. http://www.conex.com.br/jjeffman -Mensagem Original- De: <[EMAIL PROTECTED]> Para: Andrew <[EMAIL PROTECTED]>; <[EMAIL PROTECTED]> Enviada em: terça-feira, 30 de janeiro de 2001 07:24 Assunto: Re: [PHP-DB] recursion > Addressed to: "Andrew" <[EMAIL PROTECTED]> > [EMAIL PROTECTED] > > ** Reply to note from "Andrew" <[EMAIL PROTECTED]> Tue, 30 Jan 2001 10:17:40 +0200 > > > > Hi, Does PHP4 support recursive function ivocation? It seemed tome > > that it does not, because the code below doesn't work properly. > > > Yes, PHP does support recursion. I don't understand what you are > trying to do. How about including an example of what comes in $arr > when the function is called, what $this->$deptree has to do with > anything and what you want the output to look like. > -- PHP Database 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]
Re: [PHP-DB] recursion
Addressed to: "Andrew" <[EMAIL PROTECTED]> [EMAIL PROTECTED] ** Reply to note from "Andrew" <[EMAIL PROTECTED]> Tue, 30 Jan 2001 10:17:40 +0200 > > Hi, Does PHP4 support recursive function ivocation? It seemed tome > that it does not, because the code below doesn't work properly. Yes, PHP does support recursion. I don't understand what you are trying to do. How about including an example of what comes in $arr when the function is called, what $this->$deptree has to do with anything and what you want the output to look like. I'm not big on OOP, but $this->$deptree does not look right. Also usually when I see a recursive function the values passed to the function when it calls itself are derived from the values passed when it was first called. > function RecPrintDeps($arr, $depth=0){ >//print_r($arr); >$depth++; > printf("%s", $HTTP_SELF, $arr[0], $arr[2]); > while(list($k,$v)=each($this->$deptree)){ > if($v[1]==$arr[0]) > $this->RecPrintDeps($v,$depth); > } > } Rick Widmer Internet Marketing Specialists http://www.developersdesk.com -- PHP Database 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]
AW: [PHP-DB] recursion
Hi Andrew, This works fine: // Prints out an array recursiv function print_array( $array, $seperator = "" ) { while ( list( $key, $val ) = each($array) ) { if ( is_array( $val ) ) { print_array( $val, $seperator." => ".$key ); } else { echo "$seperator => $key => $val\n"; } } echo "\n"; } Hope this helps. BTW: the [PHP-DB]-List isn't the right one for this question =8) Greetinx, Mike (Germany) -Ursprungliche Nachricht- Von: Andrew [mailto:[EMAIL PROTECTED]] Gesendet: Dienstag, 30. Januar 2001 09:18 An: PHP-DB Betreff: [PHP-DB] recursion Hi, Does PHP4 support recursive function ivocation? It seemed tome that it does not, because the code below doesn't work properly. function RecPrintDeps($arr, $depth=0){ //print_r($arr); $depth++; printf("%s", $HTTP_SELF, $arr[0], $arr[2]); while(list($k,$v)=each($this->$deptree)){ if($v[1]==$arr[0]) $this->RecPrintDeps($v,$depth); } } The function is a member of a class. Regards, Andrew Kozachenko Programmer Ukraine International Airlines -- PHP Database 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] -- PHP Database 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]
[PHP-DB] recursion
Hi, Does PHP4 support recursive function ivocation? It seemed tome that it does not, because the code below doesn't work properly. function RecPrintDeps($arr, $depth=0){ //print_r($arr); $depth++; printf("%s", $HTTP_SELF, $arr[0], $arr[2]); while(list($k,$v)=each($this->$deptree)){ if($v[1]==$arr[0]) $this->RecPrintDeps($v,$depth); } } The function is a member of a class. Regards, Andrew Kozachenko Programmer Ukraine International Airlines -- PHP Database 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]