Thank you arborint, you were spot on.
Now I have dug myself another hole.
I am writing an application that runs on both mysql and IBM db2 database. It was working OK until I tried to make my database access functions into class methods.
I am getting intermitant error "Parameter 1 must be a ressource but a bool was passed" on line "$result = i5_query($string);". I know that the $string is not the problem because it works once and then fails the second time. I suspect that the way I set up function fnConnectSQL may be the problem. Maybe a scope issue?
Here are the essential bits.
Code: Select all
<?php
include_once("_dbAccess_Class.php"); // Class for database access
class ClassIndex extends ClassDbAccess
{
/* ------------------------------------------------------ */
function fnTestPW($prmUsername,$prmPassword)
/* ------------------------------------------------------ */
{
if ($GLOBALS["server"] == "i5")
$conn = i5_pconnect(9.9.9.9,USER,PASSW) or die(i5_errormsg());
else
$conn = mysql_connect(9.9.9.9,USER,PASSW) or die("Could not connect.");
$string = "SELECT * FROM PWFILE where VLUSID = " . $q. $prmUsername . $q .
" and VLPWRD = " . $q . $prmPassword . $q ;
$result = $this->fnConnectSQL($string);
$row = $this->fnFetchArraySQL($result);
if ($row == TRUE)
{
// do something
}
}
}
// _dbAccess_Class.php
class ClassDbAccess
{
/* ------------------------------------------------------ */
function fnConnectSQL($string)
/* ------------------------------------------------------ */
{
if ($GLOBALS["server"] == "i5")
{
$result = i5_query($string);
if(!$result)
{
echo "Error code2: " . i5_errno($result) . "<br>\n";
echo "Error message: " . i5_errormsg($result) . "<br>\n";
}
return $result;
}
elseif ($GLOBALS["server"] == "MySql")
{
$result = mysql_query($string);
if (!$result)
{
$message = 'Invalid query: ' . mysql_error() . "\n";
$message .= 'Whole query: ' . $string;
die($message);
}
return $result;
}
}
?>