mirror of
https://github.com/lkddi/nexusphp.git
synced 2026-04-23 19:37:23 +08:00
add getMysqlColumnInfo()
This commit is contained in:
+16
-3
@@ -53,9 +53,6 @@ class DB
|
||||
if (!$result) {
|
||||
throw new DatabaseException(sprintf('[%s]: %s', $this->errno(), $this->error()));
|
||||
}
|
||||
$this->driver->query("SET NAMES UTF8");
|
||||
$this->driver->query("SET collation_connection = 'utf8_general_ci'");
|
||||
$this->driver->query("SET sql_mode=''");
|
||||
$this->isConnected = true;
|
||||
return true;
|
||||
}
|
||||
@@ -233,5 +230,21 @@ class DB
|
||||
return Capsule::table($table);
|
||||
}
|
||||
|
||||
public static function getMysqlColumnInfo($table, $column)
|
||||
{
|
||||
static $driver;
|
||||
$config = nexus_config('nexus.mysql');
|
||||
if (is_null($driver)) {
|
||||
$driver = new DBMysqli();
|
||||
$driver->connect($config['host'], $config['username'], $config['password'], 'information_schema', $config['port']);
|
||||
}
|
||||
$sql = sprintf(
|
||||
"select * from COLUMNS where TABLE_SCHEMA = '%s' and TABLE_NAME = '%s' and COLUMN_NAME = '%s'",
|
||||
$config['database'], $table, $column
|
||||
);
|
||||
$res = $driver->query($sql);
|
||||
return $driver->fetchAssoc($res);
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user