mirror of
https://github.com/lkddi/nexusphp.git
synced 2026-05-15 20:47:33 +08:00
announce support pg
This commit is contained in:
@@ -1,6 +1,8 @@
|
||||
<?php
|
||||
namespace Nexus\Database;
|
||||
|
||||
use PDOStatement;
|
||||
|
||||
interface DBInterface
|
||||
{
|
||||
public function connect($host, $username, $password, $database, $port, $driver = 'mysql');
|
||||
@@ -29,4 +31,6 @@ interface DBInterface
|
||||
|
||||
public function freeResult($result);
|
||||
|
||||
public function prepare(string $sql): PDOStatement;
|
||||
|
||||
}
|
||||
|
||||
@@ -92,4 +92,9 @@ class DBMysqli implements DBInterface
|
||||
return $mysqliResult->free_result();
|
||||
}
|
||||
|
||||
public function prepare(string $sql): \PDOStatement
|
||||
{
|
||||
throw new \RuntimeException("mysqli not supported");
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@@ -125,4 +125,9 @@ class DBPdo implements DBInterface
|
||||
return $stmt->closeCursor();
|
||||
}
|
||||
|
||||
public function prepare(string $sql): \PDOStatement
|
||||
{
|
||||
return $this->lastStmt = $this->pdo->prepare($sql);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@@ -151,6 +151,11 @@ class NexusDB
|
||||
return $this->driver->freeResult($result);
|
||||
}
|
||||
|
||||
public function prepare(string $sql)
|
||||
{
|
||||
return $this->driver->prepare($sql);
|
||||
}
|
||||
|
||||
public function isConnected()
|
||||
{
|
||||
return $this->isConnected;
|
||||
@@ -506,4 +511,15 @@ class NexusDB
|
||||
return compact('version', 'match', 'minVersion', 'dbType');
|
||||
}
|
||||
|
||||
public static function unixTimestampField(string $field): string
|
||||
{
|
||||
if (self::isMysql()) {
|
||||
return sprintf("UNIX_TIMESTAMP(%s)", $field);
|
||||
} elseif (self::isPgsql()) {
|
||||
return sprintf("EXTRACT(EPOCH FROM %s)", $field);
|
||||
} else {
|
||||
throw new \RuntimeException('Not supported database.');
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@@ -65,3 +65,8 @@ function mysql_free_result($result)
|
||||
{
|
||||
return NexusDB::getInstance()->freeResult($result);
|
||||
}
|
||||
|
||||
function mysql_prepare(string $sql): \PDOStatement
|
||||
{
|
||||
return NexusDB::getInstance()->prepare($sql);
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user