I posted before, but have now narrowed my problem down to this method.
At the start of the method, I test to make sure that I have a
resource, a pointer to data returned from a database. This test is
coming back true, so the next line runs, which attempts to get the
next row from the dataset. This brings back nothing. On the queries
I'm running right now, the first row will be fetched, but then no
further rows. If I expect 20 rows back, I get one, then 19 errors. I
use phpMyAdmin to run the query in another environment, to be sure of
what I should be expecting.
Any ideas why the resource pointer might still test valid, yet return
nothing?
/**
* 11-04-03 - it is important that the resource which points to the
returned dataset gets passed into this method
* by reference, not by copy, or else, in the outside code that is
calling this method, the pointer in that resource
* will never advance to the next resource row.
*/
function dsRowIntoArrayWithStringIndex(&$dsResult) {
// 11-04-03 - this first lines test to see if anything came back
from the datastore
if (is_resource($dsResult)) {
$row = mysql_fetch_array($dsResult, MYSQL_ASSOC);
$row = $this->stripslashesFromEntryWithKeyIndex($row);
return $row;
} else {
$this->resultsObject->addToErrorResults("In
dsRowIntoArrayWithStringIndex(), in the class McFormatResultsMySql, we
expected the method to be handed a pointer to a database return
resource, but we were not.");
}
} 5 1989
lawrence wrote: Any ideas why the resource pointer might still test valid, yet return nothing?
The variable still holds a resource (that's what you are testing).
But the resource may be no longer valid (the database connection may
have been closed by the server).
On the manual I found the mysql_ping() function. http://www.php.net/mysql_ping
Never used it, but it might be what you need (PHP >= 4.3.0)
--
--= my mail box only accepts =--
--= Content-Type: text/plain =--
--= Size below 10001 bytes =--
Pedro Graca <he****@hotpop.com> wrote in message news:<c2*************@ID-203069.news.uni-berlin.de>... lawrence wrote: Any ideas why the resource pointer might still test valid, yet return nothing?
The variable still holds a resource (that's what you are testing). But the resource may be no longer valid (the database connection may have been closed by the server).
On the manual I found the mysql_ping() function. http://www.php.net/mysql_ping
Never used it, but it might be what you need (PHP >= 4.3.0)
Well, if it is available since 4.3 then I can't use it, since part of
my projects goal is to stay backwards compatible to 4.0.6. I guess I
can test php versions and run ping if the version is right, I do that
in some special cases, but for the most part I hate doing that.
Also, it is a bit of a band-aid that doesn't solve the real problem.
The real problem is why the connection goes dead? Since this code was
working a week ago, and now isn't, I need to look for something I've
done in the last week that has caused the resource pointer to become
invalid between loops. Any suggestions about what that might be?
Clearly, I'm not over writing the variable, since it still tests true
as a resource. I have a for() loop in my code, and the code works
correctly during the first loop, but then I get nothing back on the
rest of the iterations through the loop.
What kind of things might cause the database return to be lost?
I'm not sure how this would work in PHP, but in other languages I've
implemented a 'ping' from a simple "SELECT 1" type of query.
Wish PHP had genuine, real exception handling, that would solve a lot
of database problems. (I don't mean an error function handler ;-/ )
Jamie
lawrence <lk******@geocities.com> wrote: Pedro Graca <he****@hotpop.com> wrote in message news:<c2*************@ID-203069.news.uni-berlin.de>... lawrence wrote: > Any ideas why the resource pointer might still test valid, yet return > nothing?
The variable still holds a resource (that's what you are testing). But the resource may be no longer valid (the database connection may have been closed by the server).
On the manual I found the mysql_ping() function. http://www.php.net/mysql_ping
Never used it, but it might be what you need (PHP >= 4.3.0)
Well, if it is available since 4.3 then I can't use it, since part of my projects goal is to stay backwards compatible to 4.0.6. I guess I can test php versions and run ping if the version is right, I do that in some special cases, but for the most part I hate doing that.
Also, it is a bit of a band-aid that doesn't solve the real problem. The real problem is why the connection goes dead? Since this code was working a week ago, and now isn't, I need to look for something I've done in the last week that has caused the resource pointer to become invalid between loops. Any suggestions about what that might be? Clearly, I'm not over writing the variable, since it still tests true as a resource. I have a for() loop in my code, and the code works correctly during the first loop, but then I get nothing back on the rest of the iterations through the loop.
What kind of things might cause the database return to be lost? th******@yahoo.com wrote in message news:<p2k2c.494072$na.1169935@attbi_s04>... I'm not sure how this would work in PHP, but in other languages I've implemented a 'ping' from a simple "SELECT 1" type of query.
Wish PHP had genuine, real exception handling, that would solve a lot of database problems. (I don't mean an error function handler ;-/ )
Jamie
I'm a little confused. If I run "SELECT 1" as a ping, then suddenly
I've got a pointer to a new return, yes? It doesn't bring the old
pointer back to life, yes? Or did you mean that this is a good way to
test and make sure the database connection is still there?
I wish I had more control over things. Where are the database returns
held, in MySql or in PHP? If in MySql, can I send a message to MySql
and say, "Keep holding this, I'm not done yet?" Is there a list of ids
of all recent database returns?
Maybe its moot, I've decided to redo the whole damn thing. I've wasted
3 days on this and I'm not willing to waste a 4th. But it would have
been nice to figure out what was really going on.
lawrence <lk******@geocities.com> wrote: Pedro Graca <he****@hotpop.com> wrote in message news:<c2*************@ID-203069.news.uni-berlin.de>... lawrence wrote: > Any ideas why the resource pointer might still test valid, yet return > nothing?
The variable still holds a resource (that's what you are testing). But the resource may be no longer valid (the database connection may have been closed by the server).
On the manual I found the mysql_ping() function. http://www.php.net/mysql_ping
Never used it, but it might be what you need (PHP >= 4.3.0)
Well, if it is available since 4.3 then I can't use it, since part of my projects goal is to stay backwards compatible to 4.0.6. I guess I can test php versions and run ping if the version is right, I do that in some special cases, but for the most part I hate doing that.
Also, it is a bit of a band-aid that doesn't solve the real problem. The real problem is why the connection goes dead? Since this code was working a week ago, and now isn't, I need to look for something I've done in the last week that has caused the resource pointer to become invalid between loops. Any suggestions about what that might be? Clearly, I'm not over writing the variable, since it still tests true as a resource. I have a for() loop in my code, and the code works correctly during the first loop, but then I get nothing back on the rest of the iterations through the loop.
What kind of things might cause the database return to be lost?
This is absolutely killing me. A whole week has gone by and I still
can't fix this. And it was working before, so I just can figure out
what is wrong. I've rewritten the whole database connect system so
there is less masking and less wrapping and everything is more direct,
but I still face the same problem - I run a call against a database, I
get back a result, I go into a loop to print out the results, the
first row works comes back, and I get nothing thereafter.
I have a select object that has member objects - a query object and
then a getResults object. The query object works perfectly and runs
the query and comes back with a valid database pointer. The pointer is
then given to the getResults object. The getResults object is supposed
to return rows. It works the first time, and not thereafter. The
pointer to the database return is stored as a class variable in the
getResults object. Again, this works go get the first row. But somehow
after the first row the pointer goes dead.
Below is the class, if anyone can see why the pointer goes dead, I'd
be very grateful. Again, getRowAsArrayWithStringIndex() works for the
first row but not thereafter. Why? getCountOfReturn gets an accurate
count.
class McDatastoreResultsMySql {
var $datastoreResultsPointer = null;
var $resultsObject = null;
function McDatastoreResultsMySql() {
$controllerForAll = & getController();
$this->resultsObject = & $controllerForAll->getObject("McResults", "
in the constructor of the class McDatastoreResultsMySql.");
}
function setInfoResourcePointer($results) {
if (is_resource($results)) {
$className = get_class($this->formatObject);
$this->resultsObject->debugNotes("In setInfoResourcePointer(), in
the class McDatastoreResultsMySql, we've been given a pointer to a
database resource and now assign to our class variable.",
"McDatastoreResults");
$this->datastoreResultsPointer = $results;
} else {
$this->resultsObject->addToErrorResults("In
setInfoResourcePointer(), in the class McDatastoreResultsMySql, we
expected to be given a pointer to a database resource, but we were
not.", "McDatastoreResultsMySql");
}
}
/**
* 12-24-03 - getter
*
* We cannot call getRowAsArrayWithStringIndex() in a loop unless we
know how many items there are in the return.
* Actually, there are other ways, but this is one.
*
* $this->datastoreResultsPointer - this is a resource pointer,
pointing to the data returned from the last SELECT call
* to the datastore. Belongs to the parent class,
McDatastoreResultsFormat
*
* returns integer
*/
function getCountOfReturn() {
if (is_resource($this->datastoreResultsPointer)) {
$numberOfRowsReturned =
mysql_num_rows($this->datastoreResultsPointer);
return $numberOfRowsReturned;
} else {
$this->resultsObject->addToErrorResults("In the getCountOfReturn(),
in the class McDatastoreResultsMySql , we expected to be given a
pointer to data returned from the database during the last SELECT
call. Instead we got: $this->datastoreResultsPointer ");
}
}
/**
* 11-04-03 - it is important that the resource which points to the
returned dataset gets passed into this method
* by reference, not by copy, or else, in the outside code that is
calling this method, the pointer in that resource
* will never advance to the next resource row.
*/
function getRowAsArrayWithStringIndex() {
// 11-04-03 - this first lines test to see if anything came back
from the datastore
if (is_resource($this->datastoreResultsPointer)) {
$row = mysql_fetch_assoc($this->datastoreResultsPointer);
$row = $this->stripslashesFromEntryWithKeyIndex($row);
return $row;
} else {
$this->resultsObject->addToErrorResults("In
getRowAsArrayWithStringIndex(), in the class McDatastoreResultsMySql,
we expected the method to be handed a pointer to a database return
resource, but we were not.");
}
}
/**
* 03-08-04 - manipulator
*
* A private method for getting the back slashes out of data returned
from a database.
*
* @param - $entry - array - this method expects to be handed a one
dimensional array, one row of a database return,
* which we then loop through and run stripslashes on the values of
every field, then we return the processed array
*
* private
* returns array - one dimensional
*/
function stripslashesFromEntryWithKeyIndex($entry) {
if (is_array($entry)) {
while (list($key, $val) = each($entry)) {
$entry[$key] = stripslashes($val);
}
} else {
$this->resultsObject->addToErrorResults("In
stripslashesFromEntryWithKeyIndex(), in the class
McDatastoreResultsMySql, we expected the method to be handed an array,
but it was not.");
}
return $entry;
}
}
?> This thread has been closed and replies have been disabled. Please start a new discussion. Similar topics
by: lawrence |
last post by:
If I do something like :
$result = mysql_query($query);
$dbArray = dbResultIntoKeyArray($result);
and this is the function:
function dbResultIntoKeyArray($result) {
|
by: lawrence |
last post by:
I had some code that worked fine for several weeks, and then yesterday
it stopped working. I'm not sure what I did. Nor can I make out why it
isn't working. I'm running a query that should return 3...
|
by: pescott |
last post by:
Hello people, I could really use your help on this one... I have script
to upload image data to a database, but all that is uploaded is the
decription, not the data BLOB itself. There must be...
|
by: mikey_boy |
last post by:
Hello! Curious if anyone could give me a hand. I wrote this PHP
script with makes a simple connection to a mysql database called
firstdb and just pulls back the results and displays on the...
|
by: Alan Johnson |
last post by:
I am trying to create an automatic resource manager that works very much
the same as std::auto_ptr. However, I have a compile error I cannot
figure out. The following program demonstrates the...
|
by: jacob navia |
last post by:
Valid pointers have two states. Either empty (NULL), or filled with an
address that must be at a valid address.
Valid addresses are:
1) The current global context. The first byte of the data...
|
by: Terry |
last post by:
There are a number of things about using unmanaged resources in Windows
Forms programming that is unclear to me.
In C++, if you loaded an icon resource using "ExtractIcon()", the resource
was...
|
by: 47computers |
last post by:
Maybe this is something simple, maybe I just don't see it...
I recently did a test upgrade from MySQL 4 to 5.0.19, and most
everything seems to be working great. I also upgraded my PHP to 5.1.2...
|
by: 47computers |
last post by:
Maybe this is something simple, maybe I just don't see it...
I recently did a test upgrade from PHP 4 to 5.1.2 on my Slackware 10.0
Linux box, and most
everything seems to be working great. I...
|
by: CloudSolutions |
last post by:
Introduction:
For many beginners and individual users, requiring a credit card and email registration may pose a barrier when starting to use cloud servers. However, some cloud server providers now...
|
by: Faith0G |
last post by:
I am starting a new it consulting business and it's been a while since I setup a new website. Is wordpress still the best web based software for hosting a 5 page website? The webpages will be...
|
by: isladogs |
last post by:
The next Access Europe User Group meeting will be on Wednesday 3 Apr 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM).
In this session, we are pleased to welcome former...
|
by: taylorcarr |
last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
|
by: Charles Arthur |
last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
|
by: aa123db |
last post by:
Variable and constants
Use var or let for variables and const fror constants.
Var foo ='bar';
Let foo ='bar';const baz ='bar';
Functions
function $name$ ($parameters$) {
}
...
|
by: ryjfgjl |
last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
|
by: emmanuelkatto |
last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud.
Please let me know.
Thanks!
Emmanuel
|
by: BarryA |
last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
| | |