RE: [PHP] references a functions
What happened when you tried? -Original Message- From: javier [mailto:[EMAIL PROTECTED]] Sent: Thursday, April 04, 2002 1:01 PM To: [EMAIL PROTECTED] Subject: [PHP] references a functions I trying to code a kind of DB wrapper. So when is dbQuery turn I run into trouble. I read in php manual that refrences are not like C pointers. They just point to the same content. I want to return the result from a mysql_query but if I do something like this: function bdConsultar($strCon) { $idRes = @mysql_query($strCon); return $idRes; } Should be called like this? $myID = bdConsultar(Select * from users); -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
Re: [PHP] references a functions
Note that you rarely change a result set, so there is very little point in returning a reference to it given PHP's shallow copy implementation. And in your case you are just returning a resource id which you definitely aren't going to change. But if for some reason you feel it is important (please explain why) then this is the syntax: function bdConsultar($strCon) { $idRes = mysql_query($strCon); return $idRes; } $myID = bdConsultar(Select * from users); But again, I don't think you are quite understanding references. -Rasmus On Thu, 4 Apr 2002, javier wrote: I trying to code a kind of DB wrapper. So when is dbQuery turn I run into trouble. I read in php manual that refrences are not like C pointers. They just point to the same content. I want to return the result from a mysql_query but if I do something like this: function bdConsultar($strCon) { $idRes = mysql_query($strCon); return $idRes; } Should be called like this? $myID = bdConsultar(Select * from users); -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
Re: [PHP] references a functions
I thought that apart from returning an id the result set was created within the scope of the function so when the function finishes the resulted was deleted; But since is just an id an the result is stored somewhere else I wouldn't need any reference. btw where can I read about references besides php manual? Rasmus Lerdorf wrote: Note that you rarely change a result set, so there is very little point in returning a reference to it given PHP's shallow copy implementation. And in your case you are just returning a resource id which you definitely aren't going to change. But if for some reason you feel it is important (please explain why) then this is the syntax: function bdConsultar($strCon) { $idRes = mysql_query($strCon); return $idRes; } $myID = bdConsultar(Select * from users); But again, I don't think you are quite understanding references. -Rasmus -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
Re: [PHP] references a functions
Opossed to my thoughts worked fine. Rick Emery wrote: What happened when you tried? -Original Message- From: javier [mailto:[EMAIL PROTECTED]] Sent: Thursday, April 04, 2002 1:01 PM To: [EMAIL PROTECTED] Subject: [PHP] references a functions I trying to code a kind of DB wrapper. So when is dbQuery turn I run into trouble. I read in php manual that refrences are not like C pointers. They just point to the same content. I want to return the result from a mysql_query but if I do something like this: function bdConsultar($strCon) { $idRes = @mysql_query($strCon); return $idRes; } Should be called like this? $myID = bdConsultar(Select * from users); -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php