mirror of
https://github.com/lkddi/nexusphp.git
synced 2026-05-15 20:47:33 +08:00
migrations boolean() -> smallInteger()
This commit is contained in:
@@ -3,7 +3,7 @@ namespace Nexus\Database;
|
||||
|
||||
interface DBInterface
|
||||
{
|
||||
public function connect($host, $username, $password, $database, $port);
|
||||
public function connect($host, $username, $password, $database, $port, $driver = 'mysql');
|
||||
|
||||
public function query(string $sql);
|
||||
|
||||
@@ -29,4 +29,4 @@ interface DBInterface
|
||||
|
||||
public function freeResult($result);
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
@@ -10,7 +10,7 @@ class DBMysqli implements DBInterface
|
||||
{
|
||||
private $mysqli;
|
||||
|
||||
public function connect($host, $username, $password, $database, $port)
|
||||
public function connect($host, $username, $password, $database, $port, $driver = 'mysql')
|
||||
{
|
||||
$mysqli = new \mysqli($host, $username, $password, $database, $port);
|
||||
/* check connection */
|
||||
|
||||
@@ -8,10 +8,9 @@ class DBPdo implements DBInterface
|
||||
private $driver;
|
||||
private $lastStmt;
|
||||
|
||||
public function connect($host, $username, $password, $database, $port)
|
||||
public function connect($host, $username, $password, $database, $port, $driver = 'mysql')
|
||||
{
|
||||
$driver = $this->driver = nexus_config('nexus.database.default');
|
||||
|
||||
$this->driver = $driver;
|
||||
if ($driver === 'mysql') {
|
||||
$dsn = "mysql:host={$host};port={$port};dbname={$database};charset=utf8mb4";
|
||||
} elseif ($driver === 'pgsql') {
|
||||
|
||||
@@ -63,9 +63,9 @@ class NexusDB
|
||||
return self::$instance = $instance;
|
||||
}
|
||||
|
||||
public function connect($host, $username, $password, $database, $port)
|
||||
public function connect($host, $username, $password, $database, $port, $driver = 'mysql')
|
||||
{
|
||||
$result = $this->driver->connect($host, $username, $password, $database, $port);
|
||||
$result = $this->driver->connect($host, $username, $password, $database, $port, $driver);
|
||||
if (!$result) {
|
||||
throw new DatabaseException(sprintf('[%s]: %s', $this->errno(), $this->error()));
|
||||
}
|
||||
@@ -78,8 +78,9 @@ class NexusDB
|
||||
if ($this->isConnected()) {
|
||||
return null;
|
||||
}
|
||||
$config = nexus_config('nexus.mysql');
|
||||
return $this->connect($config['host'], $config['username'], $config['password'], $config['database'], $config['port']);
|
||||
$dbType = self::getConnectionName();
|
||||
$config = nexus_config('nexus.database.connections.' . $dbType);
|
||||
return $this->connect($config['host'], $config['username'], $config['password'], $config['database'], $config['port'], $dbType);
|
||||
}
|
||||
|
||||
public function query(string $sql)
|
||||
@@ -485,6 +486,4 @@ class NexusDB
|
||||
return $indexesNames;
|
||||
}
|
||||
|
||||
|
||||
|
||||
}
|
||||
|
||||
@@ -1,9 +1,9 @@
|
||||
<?php
|
||||
use Nexus\Database\NexusDB;
|
||||
|
||||
function mysql_connect($host, $username, $password, $database, $port)
|
||||
function mysql_connect($host, $username, $password, $database, $port, $driver = 'mysql')
|
||||
{
|
||||
return NexusDB::getInstance()->connect($host, $username, $password, $database, $port);
|
||||
return NexusDB::getInstance()->connect($host, $username, $password, $database, $port, $driver);
|
||||
}
|
||||
|
||||
function mysql_errno()
|
||||
|
||||
+30
-11
@@ -36,7 +36,7 @@ class Install
|
||||
protected array $requiredExtensions = [
|
||||
'ctype', 'curl', 'fileinfo', 'json', 'mbstring', 'openssl', 'pdo_mysql', 'tokenizer', 'xml',
|
||||
'mysqli', 'bcmath', 'redis', 'gd', 'gmp', 'Zend OPcache', 'pcntl', 'posix', 'sockets', 'zip', 'intl',
|
||||
'sqlite3', 'pdo_sqlite'
|
||||
'sqlite3', 'pdo_sqlite', 'pdo_pgsql',
|
||||
];
|
||||
|
||||
protected array $conflictExtensions = [
|
||||
@@ -156,11 +156,18 @@ class Install
|
||||
|
||||
public function listExistsTable()
|
||||
{
|
||||
$sql = 'show tables';
|
||||
if (NexusDB::isMysql()) {
|
||||
$schema = nexus_env('DB_DATABASE');
|
||||
} else if (NexusDB::isPgsql()) {
|
||||
$schema = 'public';
|
||||
} else {
|
||||
throw new \RuntimeException('Invalid DB_CONNECTION');
|
||||
}
|
||||
$sql = "SELECT table_name FROM information_schema.tables WHERE table_schema = '$schema'";
|
||||
$res = sql_query($sql);
|
||||
$data = [];
|
||||
while ($row = mysql_fetch_row($res)) {
|
||||
$data[] = $row[0];
|
||||
while ($row = mysql_fetch_assoc($res)) {
|
||||
$data[] = $row['table_name'];
|
||||
}
|
||||
return $data;
|
||||
}
|
||||
@@ -554,7 +561,8 @@ class Install
|
||||
}
|
||||
$this->doLog("[CREATE ENV] final newData: " . json_encode($newData));
|
||||
unset($key, $value);
|
||||
mysql_connect($newData['DB_HOST'], $newData['DB_USERNAME'], $newData['DB_PASSWORD'], $newData['DB_DATABASE'], (int)$newData['DB_PORT']);
|
||||
//check
|
||||
mysql_connect($newData['DB_HOST'], $newData['DB_USERNAME'], $newData['DB_PASSWORD'], $newData['DB_DATABASE'], (int)$newData['DB_PORT'], $newData['DB_CONNECTION']);
|
||||
$redis = new \Redis();
|
||||
$redis->connect($newData['REDIS_HOST'], $newData['REDIS_PORT'] ?: 6379);
|
||||
if (!empty($data['REDIS_PASSWORD'])) {
|
||||
@@ -723,14 +731,25 @@ class Install
|
||||
return $results;
|
||||
}
|
||||
|
||||
public function getMysqlVersionInfo(): array
|
||||
public function getDatabaseVersionInfo(): array
|
||||
{
|
||||
$sql = 'select version() as v';
|
||||
$result = NexusDB::select($sql);
|
||||
$version = $result[0]['v'];
|
||||
$minVersion = '5.7.8';
|
||||
if (NexusDB::isMysql()) {
|
||||
$sql = 'select version() as v';
|
||||
$result = NexusDB::select($sql);
|
||||
$version = $result[0]['v'];
|
||||
$minVersion = '5.7.8';
|
||||
$dbType = "mysql";
|
||||
} else if (NexusDB::isPgsql()) {
|
||||
$sql = 'SHOW server_version;';
|
||||
$result = NexusDB::select($sql);
|
||||
$version = $result[0]['server_version'];
|
||||
$minVersion = '16.0';
|
||||
$dbType = "pgsql";
|
||||
} else {
|
||||
throw new \RuntimeException('Not supported database.');
|
||||
}
|
||||
$match = version_compare($version, $minVersion, '>=');
|
||||
return compact('version', 'match', 'minVersion');
|
||||
return compact('version', 'match', 'minVersion', 'dbType');
|
||||
}
|
||||
|
||||
public function getRedisVersionInfo(): array
|
||||
|
||||
@@ -103,7 +103,7 @@ if ($currentStep == 4) {
|
||||
$symbolicLinks = $settingTableRows['symbolic_links'];
|
||||
$tableRows = $settingTableRows['table_rows'];
|
||||
$pass = $settingTableRows['pass'];
|
||||
$mysqlInfo = $install->getMysqlVersionInfo();
|
||||
$mysqlInfo = $install->getDatabaseVersionInfo();
|
||||
$redisInfo = $install->getREdisVersionInfo();
|
||||
while ($isPost) {
|
||||
set_time_limit(300);
|
||||
@@ -189,10 +189,10 @@ if (
|
||||
echo sprintf('This step will merge <code>%s</code> to <code>%s</code>, then insert into database', $tableRows[1]['label'], $tableRows[0]['label']);
|
||||
echo '</div>';
|
||||
if (!$mysqlInfo['match']) {
|
||||
echo sprintf('<div class="text-red-700 pt-10">MySQL version: %s is too low, please use the newest version of 5.7 or above.</div>', $mysqlInfo['version']);
|
||||
echo sprintf('<div class="text-red-700 pt-10">%s version: %s is too low, please use the newest version of %s or above.</div>', $mysqlInfo['dbType'], $mysqlInfo['version'], $mysqlInfo['minVersion']);
|
||||
}
|
||||
if (!$redisInfo['match']) {
|
||||
echo sprintf('<div class="text-red-700 pt-10">Redis version: %s is too low, please use 2.0.0 or above.</div>', $redisInfo['version']);
|
||||
echo sprintf('<div class="text-red-700 pt-10">Redis version: %s is too low, please use %s or above.</div>', $redisInfo['version'], $redisInfo['minVersion']);
|
||||
}
|
||||
} elseif ($currentStep == 5) {
|
||||
echo $install->renderForm($userFormControls, '1/2', '1/4', '3/4');
|
||||
|
||||
@@ -156,7 +156,7 @@ if ($currentStep == 4) {
|
||||
$symbolicLinks = $settingTableRows['symbolic_links'];
|
||||
$tableRows = $settingTableRows['table_rows'];
|
||||
$pass = $settingTableRows['pass'];
|
||||
$mysqlInfo = $update->getMysqlVersionInfo();
|
||||
$mysqlInfo = $update->getDatabaseVersionInfo();
|
||||
$redisInfo = $update->getRedisVersionInfo();
|
||||
while ($isPost) {
|
||||
set_time_limit(300);
|
||||
|
||||
Reference in New Issue
Block a user