|
@@ -58,6 +58,7 @@
|
|
|
namespace loyalsoft;
|
|
|
|
|
|
use \PDO;
|
|
|
+use \PDOException;
|
|
|
|
|
|
/**
|
|
|
* DAO, data access object.
|
|
@@ -170,7 +171,7 @@ class dao {
|
|
|
* @return void
|
|
|
*/
|
|
|
public function __construct() {
|
|
|
-
|
|
|
+
|
|
|
}
|
|
|
|
|
|
/**
|
|
@@ -342,7 +343,7 @@ class dao {
|
|
|
/* Get the records count. */
|
|
|
try {
|
|
|
$row = $this->dbh->query($sql)->fetch(PDO::FETCH_OBJ);
|
|
|
- } catch (PDOException $e) {
|
|
|
+ } catch (\PDOException $e) {
|
|
|
$this->sqlError($e);
|
|
|
}
|
|
|
// CLogUtil_HP::paylog($sql);
|
|
@@ -572,8 +573,9 @@ class dao {
|
|
|
* @return object the PDOStatement object.
|
|
|
*/
|
|
|
public function query($sql = '') {
|
|
|
- if (!empty(dao::$errors))
|
|
|
+ if (!empty(dao::$errors)) {
|
|
|
return new PDOStatement(); // If any error, return an empty statement object to make sure the remain method to execute.
|
|
|
+ }
|
|
|
|
|
|
if ($sql) {
|
|
|
if (is_null($this->sqlobj)) {
|
|
@@ -592,7 +594,7 @@ class dao {
|
|
|
} else {
|
|
|
return $this->dbh->query($sql);
|
|
|
}
|
|
|
- } catch (PDOException $e) {
|
|
|
+ } catch (\PDOException $e) {
|
|
|
$this->sqlError($e);
|
|
|
}
|
|
|
}
|
|
@@ -631,7 +633,7 @@ class dao {
|
|
|
/* Get the records count. */
|
|
|
try {
|
|
|
$row = $this->dbh->query($sql)->fetch(PDO::FETCH_OBJ);
|
|
|
- } catch (PDOException $e) {
|
|
|
+ } catch (\PDOException $e) {
|
|
|
$this->sqlError($e);
|
|
|
}
|
|
|
|
|
@@ -674,7 +676,7 @@ class dao {
|
|
|
try {
|
|
|
$this->reset();
|
|
|
return $this->dbh->exec($sql);
|
|
|
- } catch (PDOException $e) {
|
|
|
+ } catch (\PDOException $e) {
|
|
|
$this->sqlError($e);
|
|
|
}
|
|
|
}
|
|
@@ -975,14 +977,14 @@ class dao {
|
|
|
public function tableExist($tableName) {
|
|
|
$this->reset();
|
|
|
$this->setMethod('select');
|
|
|
- $sql = "SELECT 1 FROM $tableName LIMIT 1";
|
|
|
+ $sql = "SELECT 1 FROM `$tableName` LIMIT 1";
|
|
|
try {
|
|
|
if ($this->slaveDBH and $this->method == 'select') {
|
|
|
$ret = $this->slaveDBH->query($sql)->fetch();
|
|
|
} else {
|
|
|
$ret = $this->dbh->query($sql)->fetch();
|
|
|
}
|
|
|
- } catch (Exception $exc) {
|
|
|
+ } catch (\Exception $exc) {
|
|
|
return false;
|
|
|
}
|
|
|
// Result is either boolean FALSE (no table found) or PDOStatement Object (table found)
|
|
@@ -992,7 +994,7 @@ class dao {
|
|
|
public function Ping() {
|
|
|
try {
|
|
|
$this->dbh->getAttribute(PDO::ATTR_SERVER_INFO);
|
|
|
- } catch (PDOException $e) {
|
|
|
+ } catch (\PDOException $e) {
|
|
|
if (strpos($e->getMessage(), 'MySQL server has gone away') !== false) {
|
|
|
return false;
|
|
|
}
|
|
@@ -1086,7 +1088,7 @@ class dao {
|
|
|
$sql = "DESC $this->table";
|
|
|
$rawFields = $this->dbh->query($sql)->fetchAll();
|
|
|
$this->dbh->setAttribute(PDO::ATTR_CASE, PDO::CASE_NATURAL);
|
|
|
- } catch (PDOException $e) {
|
|
|
+ } catch (\PDOException $e) {
|
|
|
$this->sqlError($e);
|
|
|
}
|
|
|
|