#}
if (empty($this->conn)) {
- $this->bye("Connection failed: ".$this->pdo_info($this->pdo));
+ $this->bye("Connection failed: ".$this->pdo_info());
return false;
}
$count = 0;
while ($line = fgets(STDIN)) {
+ $line = preg_replace('/^\s*(.*?)\s*;?\s*$/','$1',$line);
+ if (!$line) continue;
$count++;
#echo "$count> $line";
$this->conn->exec($line);
if ($id and preg_match('/^(\w+):(.*)/',$id,$m)) {
if (empty($conf[$id])) $conf[$id] = [];
$conf[$id] = $conf[$id] + self::pdo2h($id);
-# NB 26.10.16 $conf[$id] = array(
-# NB 26.10.16 'pdo' => $id,
-# NB 26.10.16 'type' => $m[1],
-# NB 26.10.16 );
-# NB 26.10.16 debug(self::pdo2h($id));
-# NB 26.10.16
-# NB 26.10.16 foreach (explode(' ',self::pdo_info($m[2])) as $o) {
-# NB 26.10.16 if (strpos($o,'=') === false) continue;
-# NB 26.10.16 list($k,$v) = explode('=',$o);
-# NB 26.10.16 $conf[$id][$k] = $v;
-# NB 26.10.16 }
- #debug(self::pdo_info($m[2])));
}
if (!$conf) return false;
return $hash;
}
- public static function pdo_info($pdo) {
- $infos = self::pdo2h($pdo);
- foreach ($infos as $k=>$v) {
- if (!preg_match('/^(host|dbname|name)/',$k)) unset($infos[$k]);
+ public function pdo_info() {#$pdo) {
+ $infos = [];
+
+ foreach (self::pdo2h($this->pdo) as $k=>$v) {
+ if (!preg_match('/^(host|port|dbname|name|user)/',$k)) continue;
+ $infos[] = "$k=$v";
}
+
+ return join(' ',$infos);
}
public function dump2csv() {
echo ''
#."-- Database : ".$this->name."\n"
."-- Date : ".strftime('%F %T')."\n"
- ."-- Pdo : ".$this->pdo_info($this->pdo)."\n"
- #."-- Host : ".$this->host."\n"
+ ."-- Pdo : ".$this->pdo_info()."\n"
;
# Change db type if needed