473,396 Members | 1,996 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,396 software developers and data experts.

one db query object literally kills another!

I have a very simple mySqlQuery object that takes two parameters:

1) the string query
2) the db connection resource

I tested and was certain everything is passing correctly (the string
query and the db connection resource). The first mySqlQuery object
produces just fine; but when I run it, the second mySqlQuery object (a
totally different SQL query, same db connection resource) comes back
null every time, even when there is data produced by the second query.

Here is my mySqlQuery class code:

class dbConnection {

var $dbHost,$dbPort,$dbUser,$dbPwd,$dbName;

function dbconnection($dbHost,$dbPort,$dbUser,$dbPwd,$dbNam e) {

$this->dbHost = $dbHost;

$this->dbPort = $dbPort;

$this->dbUser = $dbUser;

$this->dbPwd = $dbPwd;

$this->dbName = $dbName;

$this->dbServer = $dbHost . ":" . $dbPort;

}

function connect() {

$dbcnx = @mysql_connect($this->dbServer, $this->dbUser,
$this->dbPwd);

if (!$dbcnx) {

header("Location: error.php?msg=" . urlencode('Cannot connect to
the database'));

return false;

} else {

$dbselect = mysql_select_db($this->dbName);

}

if (!$dbselect) {
header("Location: error.php?msg=" . urlencode('Cannot select the
database'));

return false;
} else {

return $dbcnx;

}

}

function close() {

$closed = mysql_close($this->connect());

if (!$closed) {
header("Location: error.php?msg=" . urlencode('Cannot close the
connection to the database'));
return false;

}

return $closed;

}

}

class mySqlQuery {

var $query,$dbcnx; // $dbcnx is a mySqlConnection object

function mySqlQuery($query,$dbcnx) {

$this->query = $query;

$this->dbcnx = $dbcnx;

}

function runQuery() {
global $devpath,$DOCUMENT_ROOT;

$result = mysql_query($this->query, $this->dbcnx) or
die(@include("$DOCUMENT_ROOT${devpath}errors/query_error.php"));

return $result;
}



function getResult() {

$runquery = $this->runQuery();

$count = 0;

while ($row = mysql_fetch_object($runquery)) {

$result[$count] = $row;

$count++;

}

return $result;

}

function getRows($what = 'select') {

$runquery = $this->runQuery();

$count = 0;

if (strcmp(strtolower($what), 'affected') == 0) {

$row = @mysql_affected_rows($this->dbcnx);

} else {

$row = @mysql_num_rows($this->dbcnx);

}

if (!$row) {

return false;

}

return $row;

}

function freeResult() {

@mysql_free_result($this->runQuery());

}

}

Here are the calls to the class object, having to do it twice because
of the logic and nature of the calls:

$db = new dbConnection($dbHost,$dbPort,$dbUser,$dbPwd,$dbNam e);
$dbconnection = $db->connect();

// Get student completion information
$query = "SELECT * FROM intern_complete_application WHERE intern_id
= '" . $this->id . "'";
$queryInfo2 = new mySqlQuery($query,$dbconnection);
print_r($queryInfo2);
$result2 = $queryInfo2->getResult();
$objArray = (get_object_vars($result2[0])) ?
get_object_vars($result2[0]) : array();
if (sizeof($objArray) > 0) {
foreach (array_flip($objArray) as $key) {
$arrayKeyName = $this->dbNameToArrayName($key);
$this->$arrayKeyName = $result2[0]->$key;
}
$queryInfo2 = null;
}
print_r("<P>completion object<p>");
print_r($result2[0]);
$result2 = null;

// Get basic information
$query = "SELECT * FROM interns WHERE id='" . $this->id . "'";
$queryInfo = new mySqlQuery($query,$dbconnection);
print_r($queryInfo);
$result = $queryInfo->getResult();
$db->close();

print_r("<P>intern object<P>");
print_r(get_object_vars($result[0]));
print_r($result[0]);

When I run the print_r statement I see my "completion object" but I
see no "intern object"; it's null. If I comment out the entire code
block that creates the completion object, THEN the intern object shows
up in full.

I am not sure at this point of a good workaround for this, is this
normal behavior based on what you see so far?

Phil
Jul 17 '05 #1
0 1815

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

2
by: kaeli | last post by:
Okay, trying to get the for...in loop syntax and obviously doing something wrong. I have a form and a select with options. The explicit indexing I usually use works fine and alerts all the...
39
by: Chetan Raj | last post by:
Hi All, One of my friend asked this question on C++ >>> Hi, Can u give an answer to this : We have the .h files for standard library. Consider any class (such as
3
by: Dr. Oz | last post by:
Hi, I am trying to read in a query string from one page and build a link to another page based on the query string. Here's the code I am using to read in the query string: <script...
4
by: starman7 | last post by:
I have a query that seems to kill the db for our website (causes the 'Too many connections' error). I would like to avoid this! Is there a way to test the query before the db goes down? I do not...
4
by: Frank | last post by:
I have a table with the following structure: main_category| category| sub_category| answer|date Basically, the data will be along these lines: Neuro | LOC | Status | answer1|date Neuro |...
4
by: Raj | last post by:
Hi all, I have couple of questions some one plzz help 1.I have a query which run for 2 hours on my production machine, it returns 1.5 millon rows, i looked at the explain plan it is picking up...
2
by: googlegroups.dsbl | last post by:
I'm really confused here, and am wondering if someone knows what could be the issue with my TableAdapter query. A few months ago, I created a really neat program that has th ability to search by...
6
by: byb3 | last post by:
Hi, this is literally driving me mad, to me it seems the simplest thing in the world to do but I have found absolutely no way of doing it. Simply put I have a query which i'll call Query1 where it...
275
by: Astley Le Jasper | last post by:
Sorry for the numpty question ... How do you find the reference name of an object? So if i have this bob = modulename.objectname() how do i find that the name is 'bob'
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
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...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
0
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.