RE: [PHP] MySQL arrays
All that you've accomplished in your example is to store the size of the queries; you've stored no data. Second, per my previous email: DO NOT RELEASE THE RESULT RESOURCE UNTIL YOU ARE DONE WITH THE PAGE. If you want to re-use a result record set, you can with the mysql_seek() function. You do not have to make yet another query to the database with the same SELECT query. You can free the result resources when you've completed the page. -Original Message- From: Anzak Wolf [mailto:[EMAIL PROTECTED]] Sent: Tuesday, March 26, 2002 10:07 AM To: [EMAIL PROTECTED]; [EMAIL PROTECTED] Subject: RE: [PHP] MySQL arrays >CHANGE: > > $len = sizeof($this->query_id); > > $len++; > > $this->query_id = array($len=>&$q); > > mysql_free_result($q); > > return $len; > >TO: > $this->query_id[] = $q; > return sizeof($this->query_id); > >second: >$q is a resource, that is, a pointer variable. When you execute >mysql_free_result($q), you free-up the memory that it pointed to. >Therefore, when you attempt to recall its value, it is pointing to memory >that you no longer own. Hence, it is not a valid resource. Therefore, do >not free the resource. When the script completes, the memory will >automatically be de-allocated. Also, when you use the phrase "&$q", you >are >creating a pointer to a pointer; is that what you want? > I thought that &$q created a new instance ie a copy of the data rather than a pointer. That worked though I have do a $q_id-- in my num_rows method because sizeof returns 1 but the way the value is being assigned it is being put in the 0 location. Though that is not a problem. Would it be better to parse out the data into arrays that I can access later then destroy the query? for example $q = mysql_query("select * from User"); $this->query_id[] = mysql_num_rows($q); mysql_free_result($q); $len = sizeof($this->query_id) - 1; return $len; This way when I have a large number of queries stored I don't have the over head of all the pointers to the query objects or would doing this create more overhead? I'm trying to save on repeated calls to the database since it is possible that the database may change between with the first query is done and the last query is done and if they are the same query then the page would need the results to be the same. _ MSN Photos is the easiest way to share and print your photos: http://photos.msn.com/support/worldwide.aspx -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
RE: [PHP] MySQL arrays
>CHANGE: > > $len = sizeof($this->query_id); > > $len++; > > $this->query_id = array($len=>&$q); > > mysql_free_result($q); > > return $len; > >TO: > $this->query_id[] = $q; > return sizeof($this->query_id); > >second: >$q is a resource, that is, a pointer variable. When you execute >mysql_free_result($q), you free-up the memory that it pointed to. >Therefore, when you attempt to recall its value, it is pointing to memory >that you no longer own. Hence, it is not a valid resource. Therefore, do >not free the resource. When the script completes, the memory will >automatically be de-allocated. Also, when you use the phrase "&$q", you >are >creating a pointer to a pointer; is that what you want? > I thought that &$q created a new instance ie a copy of the data rather than a pointer. That worked though I have do a $q_id-- in my num_rows method because sizeof returns 1 but the way the value is being assigned it is being put in the 0 location. Though that is not a problem. Would it be better to parse out the data into arrays that I can access later then destroy the query? for example $q = mysql_query("select * from User"); $this->query_id[] = mysql_num_rows($q); mysql_free_result($q); $len = sizeof($this->query_id) - 1; return $len; This way when I have a large number of queries stored I don't have the over head of all the pointers to the query objects or would doing this create more overhead? I'm trying to save on repeated calls to the database since it is possible that the database may change between with the first query is done and the last query is done and if they are the same query then the page would need the results to be the same. _ MSN Photos is the easiest way to share and print your photos: http://photos.msn.com/support/worldwide.aspx -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
RE: [PHP] MySQL arrays
CHANGE: > $len = sizeof($this->query_id); > $len++; > $this->query_id = array($len=>&$q); > mysql_free_result($q); > return $len; TO: $this->query_id[] = $q; return sizeof($this->query_id); second: $q is a resource, that is, a pointer variable. When you execute mysql_free_result($q), you free-up the memory that it pointed to. Therefore, when you attempt to recall its value, it is pointing to memory that you no longer own. Hence, it is not a valid resource. Therefore, do not free the resource. When the script completes, the memory will automatically be de-allocated. Also, when you use the phrase "&$q", you are creating a pointer to a pointer; is that what you want? >-Original Message- >From: Anzak Wolf [mailto:[EMAIL PROTECTED]] >Sent: Tuesday, March 26, 2002 9:09 AM >To: [EMAIL PROTECTED] >Subject: [PHP] MySQL arrays > > >I'm trying to do something a little different in my database class I have a >method to do the query and store it in an array. > >function query ($s = "") { > $q = mysql_query($s,$this->database_connect_id); > if (!$q) { > $tools->error(array("Query Resulted in NULL value")); > return 0; > } > $len = sizeof($this->query_id); > $len++; > $this->query_id = array($len=>&$q); > mysql_free_result($q); > return $len; >} > >function num_rows($q_id) { > // Set temp array to the selected query > $tq = &$this->query_id[$q_id]; > $rows = mysql_num_rows($tq); > return $rows; >} > >When I do a var_dump of the two key vars I get the following > >var_dump($this->query); >array(1) { > [1]=> > resource(2) of type (mysql result) >} >var_dump($tq); >resource(2) of type (Unknown) > >Here is the error that happens when I do the mysql_num_rows > > >Warning: 2 is not a valid MySQL result resource in >/var/www/includes/database_class.php on line 77 > >any ideas as to what I can do to fix this so that I can store query for >later use? > >-Jim > > > > > >_ >Send and receive Hotmail on your mobile device: http://mobile.msn.com > > >-- >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 > _ MSN Photos is the easiest way to share and print your photos: http://photos.msn.com/support/worldwide.aspx -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
RE: [PHP] MySQL arrays
Sorry my mistake the array is $this->query_id the function is $query I still get the same results though. >From: Rick Emery <[EMAIL PROTECTED]> >To: 'Anzak Wolf' <[EMAIL PROTECTED]>, [EMAIL PROTECTED] >Subject: RE: [PHP] MySQL arrays >Date: Tue, 26 Mar 2002 09:23:11 -0600 >MIME-Version: 1.0 >Received: from [216.92.131.4] by hotmail.com (3.2) with ESMTP id >MHotMailBE69DDDA00B840042A0FD85C8304065D0; Tue, 26 Mar 2002 07:25:15 -0800 >Received: (qmail 25557 invoked by uid 1010); 26 Mar 2002 15:24:18 - >Received: (qmail 25534 invoked from network); 26 Mar 2002 15:24:16 - >From php-general-return-90196-anzak Tue, 26 Mar 2002 07:26:42 -0800 >Mailing-List: contact [EMAIL PROTECTED]; run by ezmlm >Precedence: bulk >list-help: <mailto:[EMAIL PROTECTED]> >list-unsubscribe: <mailto:[EMAIL PROTECTED]> >list-post: <mailto:[EMAIL PROTECTED]> >Delivered-To: mailing list [EMAIL PROTECTED] >Message-ID: ><[EMAIL PROTECTED]> >X-Mailer: Internet Mail Service (5.5.2653.19) > >how can you take a size of a function: $len = sizeof($this->query); >and WTF (query is a function, not an array): $tq = &$this->query[$q_id]; > >-Original Message- >From: Anzak Wolf [mailto:[EMAIL PROTECTED]] >Sent: Tuesday, March 26, 2002 9:09 AM >To: [EMAIL PROTECTED] >Subject: [PHP] MySQL arrays > > >I'm trying to do something a little different in my database class I have a >method to do the query and store it in an array. > >function query ($s = "") { > $q = mysql_query($s,$this->database_connect_id); > if (!$q) { > $tools->error(array("Query Resulted in NULL value")); > return 0; > } > $len = sizeof($this->query); > $len++; > $this->query = array($len=>&$q); > mysql_free_result($q); > return $len; >} > >function num_rows($q_id) { > // Set temp array to the selected query > $tq = &$this->query[$q_id]; > $rows = mysql_num_rows($tq); > return $rows; >} > >When I do a var_dump of the two key vars I get the following > >var_dump($this->query); >array(1) { > [1]=> > resource(2) of type (mysql result) >} >var_dump($tq); >resource(2) of type (Unknown) > >Here is the error that happens when I do the mysql_num_rows > > >Warning: 2 is not a valid MySQL result resource in >/var/www/includes/database_class.php on line 77 > >any ideas as to what I can do to fix this so that I can store query for >later use? > >-Jim > > > > > >_ >Send and receive Hotmail on your mobile device: http://mobile.msn.com > > >-- >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 > _ MSN Photos is the easiest way to share and print your photos: http://photos.msn.com/support/worldwide.aspx -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
RE: [PHP] MySQL arrays
how can you take a size of a function: $len = sizeof($this->query); and WTF (query is a function, not an array): $tq = &$this->query[$q_id]; -Original Message- From: Anzak Wolf [mailto:[EMAIL PROTECTED]] Sent: Tuesday, March 26, 2002 9:09 AM To: [EMAIL PROTECTED] Subject: [PHP] MySQL arrays I'm trying to do something a little different in my database class I have a method to do the query and store it in an array. function query ($s = "") { $q = mysql_query($s,$this->database_connect_id); if (!$q) { $tools->error(array("Query Resulted in NULL value")); return 0; } $len = sizeof($this->query); $len++; $this->query = array($len=>&$q); mysql_free_result($q); return $len; } function num_rows($q_id) { // Set temp array to the selected query $tq = &$this->query[$q_id]; $rows = mysql_num_rows($tq); return $rows; } When I do a var_dump of the two key vars I get the following var_dump($this->query); array(1) { [1]=> resource(2) of type (mysql result) } var_dump($tq); resource(2) of type (Unknown) Here is the error that happens when I do the mysql_num_rows Warning: 2 is not a valid MySQL result resource in /var/www/includes/database_class.php on line 77 any ideas as to what I can do to fix this so that I can store query for later use? -Jim _ Send and receive Hotmail on your mobile device: http://mobile.msn.com -- 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