private $db;
public $mysqli = true;
public $connected = false;
-
+ public $error = false;
function __construct($server,$user,$pass,$db,$install = false) {
$pass = trim($pass);
$db = trim($db);
+ if (!(strlen($server) && strlen($user))){
+ $this->connected = false;
+ $this->db = null;
+ return;
+ }
+
if($install) {
if(strlen($server) && ($server !== 'localhost') && ($server !== '127.0.0.1')) {
if(! dns_get_record($server, DNS_A + DNS_CNAME + DNS_PTR)) {
- notice( sprintf( t('Cannot locate DNS info for database server \'%s\''), $server));
+ $this->error = sprintf( t('Cannot locate DNS info for database server \'%s\''), $server);
$this->connected = false;
$this->db = null;
return;
$mesg = '';
- if($this->mysqli && $this->db->errno)
- logger('dba: ' . $this->db->error);
- else
+ if($this->mysqli) {
+ if($this->db->errno)
+ logger('dba: ' . $this->db->error);
+ }
+ elseif(mysql_errno($this->db))
logger('dba: ' . mysql_error($this->db));
if($result === false)
$r = array();
if($this->mysqli) {
if($result->num_rows) {
- while($x = $result->fetch_array(MYSQL_ASSOC))
+ while($x = $result->fetch_array(MYSQLI_ASSOC))
$r[] = $x;
$result->free_result();
}
}
function __destruct() {
- if($this->mysqli)
- @$this->db->close();
- else
- @mysql_close($this->db);
+ if ($this->db)
+ if($this->mysqli)
+ $this->db->close();
+ else
+ mysql_close($this->db);
}
}}
}}
+
// Function: q($sql,$args);
// Description: execute SQL query with printf style args.
// Example: $r = q("SELECT * FROM `%s` WHERE `uid` = %d",
* session data after abnormal program termination
*
*/
-
logger('dba: no database: ' . print_r($args,true));
return false;