# PDO Connection
public $conn;
public $pdo;
- public $pdo_error = PDO::ERRMODE_EXCEPTION; # See: http://php.net/manual/en/pdo.error-handling.php
- public $options;
+# NB 07.04.16 public $pdo_error = array( PDO::ATTR_ERRMODE, PDO::ERRMODE_EXCEPTION); # See: http://php.net/manual/en/pdo.error-handling.php
+ public $options = array(PDO::ATTR_ERRMODE => PDO::ERRMODE_EXCEPTION); # See: http://php.net/manual/en/pdo.error-handling.php
+ #public $options;
public $host = null;
public $port = null;
public $user = null;
$this->bye("Can't read database file `".$this->name."` type=`$this->type`",false);
}
- $this->conn = new PDO($this->pdo,$this->user,$this->password,$this->options);
+ try {
+ $this->conn = new PDO($this->pdo,$this->user,$this->password,$this->options);
+ #$this->conn = new PDO($this->pdo,$this->user,$this->password,$this->pdo_error);
+ #if (isset($this->pdo_error)) $this->conn->setAttribute($this->pdo_error[0], $this->pdo_error[1]);
+
+ } catch (PDOException $e) {
+ throw new CustomException('Connection failed: ' . $e->getMessage(), (int)$e->getCode( ));
+ self::bye('Connection failed: ' . $e->getMessage());
- if (isset($this->pdo_error)) $this->conn->setAttribute(PDO::ATTR_ERRMODE, $this->pdo_error);
+ }
if (empty($this->conn)) return false;
}
public function status() {
- if ($status=$this->type('status')) {
- $new = array();
- foreach ($status as $sql => $fct) {
- foreach ($rows = $this->rows($sql) as $i=>$r) {
- #bye($rows);
- #$fct($rows[$i]);
- #if (!$rows[$i] = $fct($r)) unset($rows[$i]);
- if ($v = $fct($r)) $new += $v;
- }
- $status = $new;
- #debug($rows);
+
+ if (!($status=$this->type('status'))) return array();
+
+ $new = array();
+ foreach ($status as $sql => $fct) {
+
+ try {
+ $sth = $this->conn->prepare($sql);
+ $sth->execute();
+ } catch(PDOException $e){
+ continue;
}
- } else {
- $status = array();
+
+ $rows = $sth->fetchAll(PDO::FETCH_BOTH);
+ foreach ($rows as $i=>$r) {
+ if ($v = $fct($r)) $new += $v;
+ }
+ #$status = $new;
+ #debug($rows);
}
+
+ $new = array(
+ 'host' => $this->host,
+ 'port' => $this->port,
+ 'name' => $this->name,
+ 'user' => $this->user,
+ #'tables' => count($this->tables()),
+ #'dbs' => count($this->dbs),
+ 'tables' => count($this->tables()),
+ )+$new;
+
+ $status = array();
+ #debug($new);
+ foreach ($new as $k=>$v) {
+ $status[] = array(
+ 'name' => $k,
+ 'value' => $v,
+ );
+ }
+
+ return $status;
+ /*
+ */
+
return array(
'host' => $this->host,
'port' => $this->port,
#'tables' => join(' ',array_keys($this->tables())),
#'dbs' => join(' ',array_values($this->dbs)),
)+$status;
+
}
public function fields($st) {