472,780 Members | 1,771 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 472,780 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 1780

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: Rina0 | last post by:
Cybersecurity engineering is a specialized field that focuses on the design, development, and implementation of systems, processes, and technologies that protect against cyber threats and...
0
by: erikbower65 | last post by:
Here's a concise step-by-step guide for manually installing IntelliJ IDEA: 1. Download: Visit the official JetBrains website and download the IntelliJ IDEA Community or Ultimate edition based on...
0
by: kcodez | last post by:
As a H5 game development enthusiast, I recently wrote a very interesting little game - Toy Claw ((http://claw.kjeek.com/))。Here I will summarize and share the development experience here, and hope it...
0
by: Taofi | last post by:
I try to insert a new record but the error message says the number of query names and destination fields are not the same This are my field names ID, Budgeted, Actual, Status and Differences ...
14
DJRhino1175
by: DJRhino1175 | last post by:
When I run this code I get an error, its Run-time error# 424 Object required...This is my first attempt at doing something like this. I test the entire code and it worked until I added this - If...
0
by: Rina0 | last post by:
I am looking for a Python code to find the longest common subsequence of two strings. I found this blog post that describes the length of longest common subsequence problem and provides a solution in...
5
by: DJRhino | last post by:
Private Sub CboDrawingID_BeforeUpdate(Cancel As Integer) If = 310029923 Or 310030138 Or 310030152 Or 310030346 Or 310030348 Or _ 310030356 Or 310030359 Or 310030362 Or...
0
by: lllomh | last post by:
Define the method first this.state = { buttonBackgroundColor: 'green', isBlinking: false, // A new status is added to identify whether the button is blinking or not } autoStart=()=>{
0
by: Mushico | last post by:
How to calculate date of retirement from date of birth

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.