Skip to content

Commit

Permalink
Fixing issue with database name and fetch error preinheimer#82
Browse files Browse the repository at this point in the history
  • Loading branch information
Luigi Guevara committed Nov 22, 2017
1 parent 4d4afc2 commit 8351a9e
Showing 1 changed file with 25 additions and 18 deletions.
43 changes: 25 additions & 18 deletions xhprof_lib/utils/Db/Pdo.php
Original file line number Diff line number Diff line change
Expand Up @@ -35,33 +35,40 @@
class Db_Pdo extends Db_Abstract
{
protected $curStmt;

public function connect()
{
$connectionString = $this->config['dbtype'] . ':host=' . $this->config['dbhost'] . ';dbname=' . $this->config['dbname'];
$db = new PDO($connectionString, $this->config['dbuser'], $this->config['dbpass']);
if ($db === FALSE)
{
xhprof_error("Could not connect to db");
$run_desc = "could not connect to db";
throw new Exception("Unable to connect to database");
return false;
}
$this->db = $db;
var_dump($this->config);
$connectionString = $this->config['dbtype'] . ':host=' . $this->config['dbhost'] . ';dbname=' . $this->config['dbname'];

if ($this->config['dbtype'] === 'sqlite')
{
$connectionString = $this->config['dbtype'] .':'.$this->config['dbname'];
}

$db = new PDO($connectionString, $this->config['dbuser'], $this->config['dbpass']);
if ($db === FALSE)
{
xhprof_error("Could not connect to db");
$run_desc = "could not connect to db";
throw new Exception("Unable to connect to database");
return false;
}
$this->db = $db;
$this->db->setAttribute(PDO::ATTR_DEFAULT_FETCH_MODE, PDO::FETCH_ASSOC);
}

public function query($sql)
{
$this->curStmt = $this->db->query($sql);
return $this->curStmt;
}

public static function getNextAssoc($resultSet)
{
return $resultSet->fetch();
}

public function escape($str)
{
$str = $this->db->quote($str);
Expand All @@ -71,22 +78,22 @@ public function escape($str)
$str = substr($str, 1);
return $str;
}

public function affectedRows()
{
if ($this->curStmt === false) {
return 0;
}
return $this->curStmt->rowCount();
}

public static function unixTimestamp($field)
{
return 'UNIX_TIMESTAMP('.$field.')';
}

public static function dateSub($days)
{
return 'DATE_SUB(CURDATE(), INTERVAL '.$days.' DAY)';
}
}
}

0 comments on commit 8351a9e

Please sign in to comment.