Update PicoDb
This commit is contained in:
parent
8cdb47b003
commit
880b4517d0
8
vendor/PicoDb/Database.php
vendored
8
vendor/PicoDb/Database.php
vendored
@ -21,14 +21,6 @@ class Database
|
||||
require_once __DIR__.'/Drivers/Sqlite.php';
|
||||
$this->pdo = new Sqlite($settings['filename']);
|
||||
break;
|
||||
/*
|
||||
case 'mysql':
|
||||
$this->pdo = new \PDO(
|
||||
'mysql:host='.$settings['hostname'].';dbname='.$settings['dbname'],
|
||||
$settings['username'],
|
||||
$settings['password']
|
||||
);
|
||||
break;*/
|
||||
|
||||
default:
|
||||
throw new \LogicException('This database driver is not supported.');
|
||||
|
59
vendor/PicoDb/Table.php
vendored
59
vendor/PicoDb/Table.php
vendored
@ -127,23 +127,8 @@ class Table
|
||||
|
||||
public function findAll()
|
||||
{
|
||||
$sql = sprintf(
|
||||
'SELECT %s FROM %s %s %s %s %s %s',
|
||||
empty($this->columns) ? '*' : implode(', ', $this->columns),
|
||||
$this->db->escapeIdentifier($this->table_name),
|
||||
implode(' ', $this->joins),
|
||||
$this->conditions(),
|
||||
$this->sql_order,
|
||||
$this->sql_limit,
|
||||
$this->sql_offset
|
||||
);
|
||||
|
||||
$rq = $this->db->execute($sql, $this->values);
|
||||
|
||||
if (false === $rq) {
|
||||
|
||||
return false;
|
||||
}
|
||||
$rq = $this->db->execute($this->buildSelectQuery(), $this->values);
|
||||
if (false === $rq) return false;
|
||||
|
||||
return $rq->fetchAll(\PDO::FETCH_ASSOC);
|
||||
}
|
||||
@ -158,23 +143,45 @@ class Table
|
||||
}
|
||||
|
||||
|
||||
public function findOneColumn($column)
|
||||
{
|
||||
$this->limit(1);
|
||||
$this->columns = array($column);
|
||||
|
||||
$rq = $this->db->execute($this->buildSelectQuery(), $this->values);
|
||||
if (false === $rq) return false;
|
||||
|
||||
return $rq->fetchColumn();
|
||||
}
|
||||
|
||||
|
||||
public function buildSelectQuery()
|
||||
{
|
||||
return sprintf(
|
||||
'SELECT %s FROM %s %s %s %s %s %s',
|
||||
empty($this->columns) ? '*' : implode(', ', $this->columns),
|
||||
$this->db->escapeIdentifier($this->table_name),
|
||||
implode(' ', $this->joins),
|
||||
$this->conditions(),
|
||||
$this->sql_order,
|
||||
$this->sql_limit,
|
||||
$this->sql_offset
|
||||
);
|
||||
}
|
||||
|
||||
|
||||
public function count()
|
||||
{
|
||||
$sql = sprintf(
|
||||
'SELECT COUNT(*) AS count FROM %s'.$this->conditions().$this->sql_order.$this->sql_limit.$this->sql_offset,
|
||||
'SELECT COUNT(*) FROM %s'.$this->conditions().$this->sql_order.$this->sql_limit.$this->sql_offset,
|
||||
$this->db->escapeIdentifier($this->table_name)
|
||||
);
|
||||
|
||||
$rq = $this->db->execute($sql, $this->values);
|
||||
if (false === $rq) return false;
|
||||
|
||||
if (false === $rq) {
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
$result = $rq->fetch(\PDO::FETCH_ASSOC);
|
||||
|
||||
return isset($result['count']) ? (int) $result['count'] : 0;
|
||||
$result = $rq->fetchColumn();
|
||||
return $result ? (int) $result : 0;
|
||||
}
|
||||
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user