|
@@ -964,19 +964,29 @@ class dao {
|
|
*/
|
|
*/
|
|
public function tableExist($tableName) {
|
|
public function tableExist($tableName) {
|
|
$this->reset();
|
|
$this->reset();
|
|
- $this->setMethod('select');
|
|
|
|
- $sql = "SELECT 1 FROM $tableName LIMIT 1";
|
|
|
|
|
|
+// $this->setMethod('select');
|
|
|
|
+ $sql = "select * from information_schema.TABLES where `TABLE_NAME` = '$tableName';";
|
|
|
|
+// var_dump($sql);
|
|
try {
|
|
try {
|
|
- if ($this->slaveDBH and $this->method == 'select') {
|
|
|
|
- $ret = $this->slaveDBH->query($sql)->fetch();
|
|
|
|
- } else {
|
|
|
|
- $ret = $this->dbh->query($sql)->fetch();
|
|
|
|
- }
|
|
|
|
|
|
+ $stmt = $this->query($sql);
|
|
|
|
+ $ret = $stmt->fetchall();
|
|
} catch (Exception $exc) {
|
|
} catch (Exception $exc) {
|
|
return false;
|
|
return false;
|
|
}
|
|
}
|
|
|
|
+// var_dump($ret);
|
|
// Result is either boolean FALSE (no table found) or PDOStatement Object (table found)
|
|
// Result is either boolean FALSE (no table found) or PDOStatement Object (table found)
|
|
- return $ret !== FALSE; # false代表表不存在
|
|
|
|
|
|
+ return $ret !== FALSE && is_array($ret) && count($ret) > 0; # false或者返回0行记录,代表表不存在
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+ public function Ping() {
|
|
|
|
+ try {
|
|
|
|
+ $this->dbh->getAttribute(PDO::ATTR_SERVER_INFO);
|
|
|
|
+ } catch (PDOException $e) {
|
|
|
|
+ if (strpos($e->getMessage(), 'MySQL server has gone away') !== false) {
|
|
|
|
+ return false;
|
|
|
|
+ }
|
|
|
|
+ }
|
|
|
|
+ return true;
|
|
}
|
|
}
|
|
|
|
|
|
/**
|
|
/**
|
|
@@ -1428,7 +1438,7 @@ class sql {
|
|
* @return object the sql object.
|
|
* @return object the sql object.
|
|
*/
|
|
*/
|
|
public function where($arg1, $arg2 = null, $arg3 = null) {
|
|
public function where($arg1, $arg2 = null, $arg3 = null) {
|
|
- if ($this->inCondition and!$this->conditionIsTrue)
|
|
|
|
|
|
+ if ($this->inCondition and ! $this->conditionIsTrue)
|
|
return $this;
|
|
return $this;
|
|
if ($arg3 !== null) {
|
|
if ($arg3 !== null) {
|
|
$value = $this->quote($arg3);
|
|
$value = $this->quote($arg3);
|
|
@@ -1449,7 +1459,7 @@ class sql {
|
|
* @return object the sql object.
|
|
* @return object the sql object.
|
|
*/
|
|
*/
|
|
public function andWhere($condition) {
|
|
public function andWhere($condition) {
|
|
- if ($this->inCondition and!$this->conditionIsTrue)
|
|
|
|
|
|
+ if ($this->inCondition and ! $this->conditionIsTrue)
|
|
return $this;
|
|
return $this;
|
|
$this->sql .= " AND $condition ";
|
|
$this->sql .= " AND $condition ";
|
|
return $this;
|
|
return $this;
|
|
@@ -1463,7 +1473,7 @@ class sql {
|
|
* @return object the sql object.
|
|
* @return object the sql object.
|
|
*/
|
|
*/
|
|
public function orWhere($condition) {
|
|
public function orWhere($condition) {
|
|
- if ($this->inCondition and!$this->conditionIsTrue)
|
|
|
|
|
|
+ if ($this->inCondition and ! $this->conditionIsTrue)
|
|
return $this;
|
|
return $this;
|
|
$this->sql .= " OR $condition ";
|
|
$this->sql .= " OR $condition ";
|
|
return $this;
|
|
return $this;
|
|
@@ -1477,7 +1487,7 @@ class sql {
|
|
* @return object the sql object.
|
|
* @return object the sql object.
|
|
*/
|
|
*/
|
|
public function eq($value) {
|
|
public function eq($value) {
|
|
- if ($this->inCondition and!$this->conditionIsTrue)
|
|
|
|
|
|
+ if ($this->inCondition and ! $this->conditionIsTrue)
|
|
return $this;
|
|
return $this;
|
|
$this->sql .= " = " . $this->quote($value);
|
|
$this->sql .= " = " . $this->quote($value);
|
|
return $this;
|
|
return $this;
|
|
@@ -1491,7 +1501,7 @@ class sql {
|
|
* @return void the sql object.
|
|
* @return void the sql object.
|
|
*/
|
|
*/
|
|
public function ne($value) {
|
|
public function ne($value) {
|
|
- if ($this->inCondition and!$this->conditionIsTrue)
|
|
|
|
|
|
+ if ($this->inCondition and ! $this->conditionIsTrue)
|
|
return $this;
|
|
return $this;
|
|
$this->sql .= " != " . $this->quote($value);
|
|
$this->sql .= " != " . $this->quote($value);
|
|
return $this;
|
|
return $this;
|
|
@@ -1505,7 +1515,7 @@ class sql {
|
|
* @return object the sql object.
|
|
* @return object the sql object.
|
|
*/
|
|
*/
|
|
public function gt($value) {
|
|
public function gt($value) {
|
|
- if ($this->inCondition and!$this->conditionIsTrue)
|
|
|
|
|
|
+ if ($this->inCondition and ! $this->conditionIsTrue)
|
|
return $this;
|
|
return $this;
|
|
$this->sql .= " > " . $this->quote($value);
|
|
$this->sql .= " > " . $this->quote($value);
|
|
return $this;
|
|
return $this;
|
|
@@ -1519,7 +1529,7 @@ class sql {
|
|
* @return object the sql object.
|
|
* @return object the sql object.
|
|
*/
|
|
*/
|
|
public function ge($value) {
|
|
public function ge($value) {
|
|
- if ($this->inCondition and!$this->conditionIsTrue)
|
|
|
|
|
|
+ if ($this->inCondition and ! $this->conditionIsTrue)
|
|
return $this;
|
|
return $this;
|
|
$this->sql .= " >= " . $this->quote($value);
|
|
$this->sql .= " >= " . $this->quote($value);
|
|
return $this;
|
|
return $this;
|
|
@@ -1533,7 +1543,7 @@ class sql {
|
|
* @return object the sql object.
|
|
* @return object the sql object.
|
|
*/
|
|
*/
|
|
public function lt($value) {
|
|
public function lt($value) {
|
|
- if ($this->inCondition and!$this->conditionIsTrue)
|
|
|
|
|
|
+ if ($this->inCondition and ! $this->conditionIsTrue)
|
|
return $this;
|
|
return $this;
|
|
$this->sql .= " < " . $this->quote($value);
|
|
$this->sql .= " < " . $this->quote($value);
|
|
|
|
|
|
@@ -1564,7 +1574,7 @@ class sql {
|
|
* @return object the sql object.
|
|
* @return object the sql object.
|
|
*/
|
|
*/
|
|
public function between($min, $max) {
|
|
public function between($min, $max) {
|
|
- if ($this->inCondition and!$this->conditionIsTrue)
|
|
|
|
|
|
+ if ($this->inCondition and ! $this->conditionIsTrue)
|
|
return $this;
|
|
return $this;
|
|
$min = $this->quote($min);
|
|
$min = $this->quote($min);
|
|
$max = $this->quote($max);
|
|
$max = $this->quote($max);
|
|
@@ -1581,7 +1591,7 @@ class sql {
|
|
*/
|
|
*/
|
|
public function in($ids) {
|
|
public function in($ids) {
|
|
// var_dump($ids);
|
|
// var_dump($ids);
|
|
- if ($this->inCondition and!$this->conditionIsTrue)
|
|
|
|
|
|
+ if ($this->inCondition and ! $this->conditionIsTrue)
|
|
return $this;
|
|
return $this;
|
|
$this->sql .= self::dbIN($ids);
|
|
$this->sql .= self::dbIN($ids);
|
|
return $this;
|
|
return $this;
|
|
@@ -1609,7 +1619,7 @@ class sql {
|
|
* @return object the sql object.
|
|
* @return object the sql object.
|
|
*/
|
|
*/
|
|
public function notin($ids) {
|
|
public function notin($ids) {
|
|
- if ($this->inCondition and!$this->conditionIsTrue)
|
|
|
|
|
|
+ if ($this->inCondition and ! $this->conditionIsTrue)
|
|
return $this;
|
|
return $this;
|
|
$this->sql .= ' NOT ' . self::dbIN($ids);
|
|
$this->sql .= ' NOT ' . self::dbIN($ids);
|
|
return $this;
|
|
return $this;
|
|
@@ -1623,7 +1633,7 @@ class sql {
|
|
* @return object the sql object.
|
|
* @return object the sql object.
|
|
*/
|
|
*/
|
|
public function like($string) {
|
|
public function like($string) {
|
|
- if ($this->inCondition and!$this->conditionIsTrue)
|
|
|
|
|
|
+ if ($this->inCondition and ! $this->conditionIsTrue)
|
|
return $this;
|
|
return $this;
|
|
$this->sql .= " LIKE " . $this->quote($string);
|
|
$this->sql .= " LIKE " . $this->quote($string);
|
|
return $this;
|
|
return $this;
|
|
@@ -1637,7 +1647,7 @@ class sql {
|
|
* @return object the sql object.
|
|
* @return object the sql object.
|
|
*/
|
|
*/
|
|
public function notLike($string) {
|
|
public function notLike($string) {
|
|
- if ($this->inCondition and!$this->conditionIsTrue)
|
|
|
|
|
|
+ if ($this->inCondition and ! $this->conditionIsTrue)
|
|
return $this;
|
|
return $this;
|
|
$this->sql .= "NOT LIKE " . $this->quote($string);
|
|
$this->sql .= "NOT LIKE " . $this->quote($string);
|
|
return $this;
|
|
return $this;
|
|
@@ -1652,7 +1662,7 @@ class sql {
|
|
* @return object the sql object.
|
|
* @return object the sql object.
|
|
*/
|
|
*/
|
|
public function findInSet($str, $strList) {
|
|
public function findInSet($str, $strList) {
|
|
- if ($this->inCondition and!$this->conditionIsTrue)
|
|
|
|
|
|
+ if ($this->inCondition and ! $this->conditionIsTrue)
|
|
return $this;
|
|
return $this;
|
|
$this->sql .= "FIND_IN_SET(" . $str . "," . $strList . ")";
|
|
$this->sql .= "FIND_IN_SET(" . $str . "," . $strList . ")";
|
|
}
|
|
}
|
|
@@ -1665,7 +1675,7 @@ class sql {
|
|
* @return object the sql object.
|
|
* @return object the sql object.
|
|
*/
|
|
*/
|
|
public function orderBy($order) {
|
|
public function orderBy($order) {
|
|
- if ($this->inCondition and!$this->conditionIsTrue)
|
|
|
|
|
|
+ if ($this->inCondition and ! $this->conditionIsTrue)
|
|
return $this;
|
|
return $this;
|
|
|
|
|
|
$order = str_replace(array('|', '', '_'), ' ', $order);
|
|
$order = str_replace(array('|', '', '_'), ' ', $order);
|