 |
|
|
View previous topic :: View next topic |
Author |
Message |
Pearus
Joined: 25 Sep 2007 Posts: 12
|
Posted: Wed Apr 30, 2008 3:19 pm Post subject: MDB2 error:unkown error:_doQuery: [Error message...] |
|
|
I really need som help - I try to do some queries - I know the database(psql) do connect correctly - but it seems that it just can take the first query....the next get the error, and the $db->query($query) get wrong!
I really cant figure out whats the problem
here is the code for the function queryDB:
if (!$ndo) {
global $dbConf;
} else {
global $dbNDO;
$dbConf = &$dbNDO;
}
$options=array(
'debug' => 2,
'persistent' => true,
//'portability' => MDB2_PORTABILITY_ALL,
);
$dsn = array(
'phptype' => 'pgsql',
'username' => $config->dbuser,
'password' => $config->dbpass,
'hostspec' => $config->dbhost,
'database' => $config->db,
);
$db =& MDB2::connect($dsn,$options);
if (PEAR::iserror($db)){
die("Cannot connect: " . $db->getMessage());
}
$db->loadModule('Extended');
$db->setFetchMode(MDB2_FETCHMODE_OBJECT);
// query database
//$info = new smarteye();
// $info->connect();
// return $info->retrieve_sites();
$queryCmd = strtolower(substr($query, 0, 6));
echo "<pre>\n";
echo "QueryCmd: $queryCmd\n";
$tmp_rowcount=0;
if($queryCmd=='select'){
echo "Orginal query: $query\n";
// echo var_dump($db->query($query));
$result=$db->query($query);
if (PEAR::isError($result)) {
// echo var_dump($result);
echo "</pre>\n";
$err=$result->getUserInfo();
echo $err;
$str=$result->getMessage();
echo '<font color="red">FEEEEEEEEEIL</font><br>';
echo $str;
}
while ($row=$result->fetchRow(DB_FETCHMODE_OBJECT)){ $out[]=$row;
// echo var_dump($row->full_name);
// echo var_dump($out);
$tmp_rowcount++;
}
$db->free();
echo "Rows 1: $tmp_rowcount</pre>\n";
if (!$dbConf['persistent']) $db->disconnect($db);
if ($tmp_rowcount != 0 ) {
return array($tmp_rowcount, $out);
} else {
die();
}
} else {
echo "Not a select query!\n";
}
}
/**
* prepareDBValue - wraps a value to secure it for sql query
*
* @param string $value data to wrap
* @return wrapped data
*/
function prepareDBValue ($value) {
return addslashes(htmlentities(html_entity_decode(stripslashes($value))));
}
/**
* shorten - shortens a string by using a global config value and appends '...'
*
* @param string $str string to shorten
* @param string $enty entry in global config containing max string length
* @return shortenend string
*/
function shorten ($str, $entry) {
global $str_maxlen;
$long = $str;
$short = false;
if (strlen($str) > $str_maxlen[$entry]) {
$str = substr($str, 0, $str_maxlen[$entry] - 3) . '...';
$short = true;
}
return array($long, $str, $short);
}
/**
* getQueryString - return the query string w/ possible exclusions
*
* @param mixed $exclude parameter keys for exclusion (optional)
* @param array $set associative array of parameters and values to set (optional)
* @return string query string
*/
function getQueryString ($exclude = null, $set = null) {
global $p;
// prepare
if (is_string($exclude)) $exclude = array($exclude);
if (!$set) $set = array();
// init
$qStr = null;
$sep = null;
// generate
foreach ($p as $key => $value) {
$current_exclude = in_array($key, $exclude);
$current_set = array_key_exists($key, $exclude);
if (!$current_exclude) {
$qStr .= $sep . $key . '=';
if (!$current_set) {
$qStr .= $value;
} else {
$qStr .= $set[$key];
}
if (!$sep) $sep = '&';
}
}
// return new query string
return $qStr;
}
and here is where the call is :
function getTimePeriods () {
$timeperiods = array();
$dbResult = queryDB('select id,description from time_periods');
if (is_array($dbResult)) {
foreach ($dbResult as $row) {
$timeperiods[$row['id']] = $row['description'];
}
}
return $timeperiods;
}
function getContacts ($exclude = null) {
$query = 'select username,concat(first_name,last_name) as full_name from contacts where username != \'[---]\'';
// $query = 'select * from contacts';
if ($exclude) {
$query .= ' and username != \'' . prepareDBValue($exclude) . '\'';
}
$query .= ' order by first_name';
//echo $query;
$dbResult = queryDB($query);
// echo var_dump('<font color="red">isabel:'.$dbResult[0].'</font>');
// echo var_dump($dbResult);
$users = array();
if (is_array($users)) {
if($dbResult){
foreach ($dbResult[1] as $row) {
echo var_dump($row->full_name);
$users[$row->username] = $row->full_name;
}
}
}
// echo var_dump($users);
return $users;
}
function getTimeZone ($id = null) {
if ($id) {
$dbResult = queryDB('select * from timezones where id=\'' . prepareDBValue($id) . '\' order by timezone');
} else {
$dbResult = queryDB('select id,timezone,time_diff from timezones order by timezone');
// echo var_dump($dbResult);
}
$timezones = array();
//echo var_dump($dbResult);
if (is_array($dbResult)) {
$num_rows=$dbResult[0];
$dbRows=$dbResult[1];
$i=0;
foreach ($dbRows as $row) {
// echo "Geir tester; $i<br>"; //var_dump($var[$i]);
$diff = $row->time_diff;
// echo var_dump($diff);
$timezones[$row->id] = $row->timezone . sprintf(' (%s%dh)', (($diff < 0) ? null : '+'), $diff);
// echo $timezones[$row->id];
$i++;
// echo $i;
}
}
// echo var_dump($timezones);
return $timezones;
}
/**
* getTimeZone - give back associative array of timezones and corresponding ids
*
* @param string $id id of timezone to search
* @return array of timezones and corresponding ids
*/
/**
* getUsers - give back associative array of users and corresponding ids
*
* @param string $exclude username of user to exclude from list
* @return array of users and corresponding ids
*/
/**
* getNotificytionMethods - give back associative array of methods and corresponding ids
*
* @param none
* @return array of methods and corresponding ids
*/
function getNotificationMethods () {
$dbResult = queryDB('select id,method from notification_methods order by method');
$methods = array();
if (is_array($dbResult)) {
foreach($dbResult as $row) {
$methods[$row['id']] = $row['method'];
}
}
return $methods;
}
/**
* getContactGroups - gives back an associative array of contactgroups and corresponding ids
*
* @param none
* @return array of contactgroups and corresponding ids
*/
function getContactGroups () {
$dbResult = queryDB('select * from contactgroups order by name');
$contactgroups = array();
if (is_array($dbResult)) {
foreach($dbResult as $row) {
$contactgroups[$row['id']] = $row['name'];
}
}
return $contactgroups;
}
/**
* getContactGroupContacts - gives back an associative array of contacts of a contact group
*
* @param string $contactgroup contactgroup to for search users
* @return array users who are members of the specified contactgroup
*/
function getContactGroupMembers ($contactgroup = null) {
if (empty($contactgroup)) return array();
$members = array();
$query = 'select distinct c.username
from contacts c
left join contactgroups_to_contacts cgc on cgc.contact_id=c.id
left join contactgroups cg on cg.id=cgc.contactgroup_id
where c.username != \'[---]\' and cg.id=\'' . $contactgroup . '\'';
$dbResult = queryDB($query);
if (is_array($dbResult)) {
foreach ($dbResult as $row) {
$members[] = $row['username'];
}
}
return $members;
}
/**
* getContactGroupShortById - returns the short name of a contact group
*
* @param string $id id of contact group
* @return string short name of contact group
*/
function getContactGroupShortById ($id) {
$dbResult = queryDB('select name_short from contactgroups where id=\'' . prepareDBValue($id) . '\'');
if (!is_array($dbResult)) return null;
if (!count($dbResult)) return null;
return $dbResult[0]['name_short'];
}
HELPP! |
|
Back to top |
|
 |
|
|
You cannot post new topics in this forum You cannot reply to topics in this forum You cannot edit your posts in this forum You cannot delete your posts in this forum You cannot vote in polls in this forum
|
|