install issue (memory exhausted) due to incorrect db open check

This commit is contained in:
Friendika 2011-03-01 16:24:22 -08:00
parent 2d4b3bee60
commit 5ff1462e1e
2 changed files with 14 additions and 6 deletions

View File

@ -16,11 +16,16 @@ class dba {
private $debug = 0; private $debug = 0;
private $db; private $db;
public $connected = false;
function __construct($server,$user,$pass,$db,$install = false) { function __construct($server,$user,$pass,$db,$install = false) {
$this->db = @new mysqli($server,$user,$pass,$db); $this->db = @new mysqli($server,$user,$pass,$db);
if((mysqli_connect_errno()) && (! $install)) if((mysqli_connect_errno()) && (! $install)) {
system_unavailable(); $this->db = null;
system_unavailable();
}
else
$this->connected = true;
} }
public function getdb() { public function getdb() {
@ -114,7 +119,7 @@ function dbg($state) {
if(! function_exists('dbesc')) { if(! function_exists('dbesc')) {
function dbesc($str) { function dbesc($str) {
global $db; global $db;
if($db) if($db->connected)
return($db->escape($str)); return($db->escape($str));
else else
return(str_replace("'","\\'",$str)); return(str_replace("'","\\'",$str));
@ -133,7 +138,7 @@ function q($sql) {
$args = func_get_args(); $args = func_get_args();
unset($args[0]); unset($args[0]);
if($db) { if($db->connected) {
$ret = $db->q(vsprintf($sql,$args)); $ret = $db->q(vsprintf($sql,$args));
return $ret; return $ret;
} }
@ -160,7 +165,10 @@ if(! function_exists('dbq')) {
function dbq($sql) { function dbq($sql) {
global $db; global $db;
$ret = $db->q($sql); if($db->connected)
$ret = $db->q($sql);
else
$ret = false;
return $ret; return $ret;
}} }}

View File

@ -1,5 +1,5 @@
<?php <?php
error_reporting(E_ERROR | E_WARNING | E_PARSE);
/** /**
* *
* Friendika * Friendika