20 $this->operations[
DbOperations::AUTO_INC]=
'ALTER TABLE {tableName} MODIFY {fieldInfos} AUTO_INCREMENT, AUTO_INCREMENT={value}';
24 $query = $this->dbInstance->query (
'SHOW TABLES' );
25 return $query->fetchAll ( \PDO::FETCH_COLUMN );
29 $fieldkeys = array ();
30 $recordset = $this->dbInstance->query (
"SHOW KEYS FROM `{$tableName}` WHERE Key_name = 'PRIMARY'" );
31 $keys = $recordset->fetchAll ( \PDO::FETCH_ASSOC );
32 foreach ( $keys as $key ) {
33 $fieldkeys [] = $key [
'Column_name'];
38 public function getForeignKeys(
string $tableName,
string $pkName, ?
string $dbName =
null): array {
39 $recordset = $this->dbInstance->query (
"SELECT *
41 information_schema.KEY_COLUMN_USAGE
43 REFERENCED_TABLE_NAME = '" . $tableName .
"'
44 AND REFERENCED_COLUMN_NAME = '" . $pkName .
"'
45 AND TABLE_SCHEMA = '" . $dbName .
"';" );
46 return $recordset->fetchAll ( \PDO::FETCH_ASSOC );
50 $fieldsInfos = array ();
51 $recordset = $this->dbInstance->query (
"SHOW COLUMNS FROM `{$tableName}`" );
52 $fields = $recordset->fetchAll ( \PDO::FETCH_ASSOC );
53 foreach ( $fields as $field ) {
54 $fieldsInfos [$field [
'Field']] = [
"Type" => $field [
'Type'],
"Nullable" => $field [
"Null"] ];
59 public function getRowNum(
string $tableName,
string $pkName,
string $condition): int {
60 $query = $this->dbInstance->query (
"SELECT num FROM (SELECT *, @rownum:=@rownum + 1 AS num FROM `{$tableName}`, (SELECT @rownum:=0) r ORDER BY {$pkName}) d WHERE " . $condition );
62 return $query->fetchColumn ( 0 );
67 public function groupConcat(
string $fields,
string $separator): string {
68 return
"GROUP_CONCAT({$fields} SEPARATOR '{$separator}')";
72 return $this->dbInstance->exec(
"SET TRANSACTION ISOLATION LEVEL $isolationLevel");