I have a page that basically lays out like this (extremely condensed):
<?PHP
require_once 'class.mysql.php';
$db_metadata = new mysql('localhost', MEMBER_U, MEMBER_P, 'metadata');
$db_metadata->connect();
$db_metadata->select();
class get { ... } //sanitize
function doSomething() {
global $dirGet;
global $db_metadata;
$db_metadata->query("SELECT intParentID_FK, strName FROM subjects
WHERE intSubjectID_PK='".$dirGet->clean('subID')."';");
$db_metadata->getResultAsTable();
}
function showDirectory() { ... }
$dir = array();
$dirGet = new get();
$dirGet->sanitize();
$db_metadata->query("SELECT intSubjectID_PK, strName FROM subjects
WHERE intParentID_FK='".$dirGet->clean('subID')."';");
for($i=1; $i<=$db_metadata->numRows(); $i++) {
$folder = $db_metadata->fetchObject();
$dir[0][$i-1] = $folder->strName;
$dir[1][$i-1] = $folder->intSubjectID_PK;
}
?>
<html><head></head><body>
<?PHP require_once '../head.php'; //makes use of class.mysql, twice //shows title bar, menu, login, etc.
doSomething();
?>
<table><tr><td>
<?
showDirectory();
?>
</td></tr></table>
</body></html>
I couldn't figure out why the query inside the function wasn't returning anything, until I looked at the log...
060606 9:36:35 37 Connect member@localhost on
37 Init DB metadata
37 Query SELECT intSubjectID_PK, strName FROM subjects WHERE intParentID_FK='1'
37 Init DB users
38 Connect admin@localhost on
38 Init DB sessions
38 Query SELECT value FROM sessioninfo WHERE SID='cbf400792a39edbfd28b840e7e6d5f8a' AND expiration>1149608195
37 Query SELECT intParentID_FK, strName FROM subjects WHERE intSubjectID_PK='1'
38 Query INSERT INTO sessioninfo VALUES('cbf400792a39edbfd28b840e7e6d5f8a', '1149609635', 'redirect|s:35:"http://localhost/directory/index.php";')
38 Query UPDATE sessioninfo SET expiration='1149609635', value='redirect|s:35:"http://localhost/directory/index.php";' WHERE SID='cbf400792a39edbfd28b840e7e6d5f8a' AND expiration>1149608195
37 Quit
38 Quit
Connection #37 is being reused from head.php, then the query inside the function obviously seems to be asking the wrong database. Shouldn't the MySQL class connect using a new number?