- Is this true for PHP?
- If so, what is the "proper" way to return NULL, if necessary, by reference?
Although not necessarily relevant to my question, here is the code I am using for the db_handler. Note that I am using an error handler to collect information. Anything
Code: Select all
function &db_call($sql, $return_type)
{
// defined return types:
// none: SQL_RESULT_NONE
// single: SQL_RESULT_SINGLE
// set: SQL_RESULT_SET
// object: SQL_RESULT_OBJECT
global $db;
// trigger_error("Looking closely at DB call:\n\n" . $sql . "\n\n" .
urldecode($sql), E_USER_NOTICE);
$result = $db->Execute($sql);
if ($result === FALSE)
{
trigger_error($db->ErrorMsg(), E_USER_ERROR);
}
elseif ($return_type == SQL_RESULT_NONE)
{
assert($result->RecordCount() == 0);
return 0;
}
elseif ($return_type == SQL_RESULT_SINGLE)
{
if ($result->RecordCount() == 1)
{
return $result->fields;
}
else
{
return NULL;
}
}
elseif ($return_type == SQL_RESULT_SET)
{
if ($result->RecordCount() > 0)
{
return $result->GetRows();
}
else
{
return NULL;
}
}
elseif ($return_type = SQL_RESULT_OBJECT)
{
return $result;
}
else
{
trigger_error('This is an unexpected condition.
Check the second arguement of db_call...
or there may be other causes', E_USER_ERROR);
return NULL; // this code will probably not happen.
}
} // END function db_call(...)