Skip to content

Commit 932822b

Browse files
dennydanekdg
authored andcommitted
MySqlDriver: Fix PDO::ATTR_CASE (#199)
fixed Cannot read an undeclared column 'Type', did you mean 'type'? when you used PDO::ATTR_CASE option
1 parent 0bcb385 commit 932822b

File tree

1 file changed

+17
-14
lines changed

1 file changed

+17
-14
lines changed

src/Database/Drivers/MySqlDriver.php

Lines changed: 17 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -131,16 +131,17 @@ public function getColumns(string $table): array
131131
{
132132
$columns = [];
133133
foreach ($this->connection->query('SHOW FULL COLUMNS FROM ' . $this->delimite($table)) as $row) {
134-
$type = explode('(', $row['Type']);
134+
$row = array_change_key_case((array) $row, CASE_LOWER);
135+
$type = explode('(', $row['type']);
135136
$columns[] = [
136-
'name' => $row['Field'],
137+
'name' => $row['field'],
137138
'table' => $table,
138139
'nativetype' => strtoupper($type[0]),
139140
'size' => isset($type[1]) ? (int) $type[1] : null,
140-
'nullable' => $row['Null'] === 'YES',
141-
'default' => $row['Default'],
142-
'autoincrement' => $row['Extra'] === 'auto_increment',
143-
'primary' => $row['Key'] === 'PRI',
141+
'nullable' => $row['null'] === 'YES',
142+
'default' => $row['default'],
143+
'autoincrement' => $row['extra'] === 'auto_increment',
144+
'primary' => $row['key'] === 'PRI',
144145
'vendor' => (array) $row,
145146
];
146147
}
@@ -152,10 +153,11 @@ public function getIndexes(string $table): array
152153
{
153154
$indexes = [];
154155
foreach ($this->connection->query('SHOW INDEX FROM ' . $this->delimite($table)) as $row) {
155-
$indexes[$row['Key_name']]['name'] = $row['Key_name'];
156-
$indexes[$row['Key_name']]['unique'] = !$row['Non_unique'];
157-
$indexes[$row['Key_name']]['primary'] = $row['Key_name'] === 'PRIMARY';
158-
$indexes[$row['Key_name']]['columns'][$row['Seq_in_index'] - 1] = $row['Column_name'];
156+
$row = array_change_key_case((array) $row, CASE_LOWER);
157+
$indexes[$row['key_name']]['name'] = $row['key_name'];
158+
$indexes[$row['key_name']]['unique'] = !$row['non_unique'];
159+
$indexes[$row['key_name']]['primary'] = $row['key_name'] === 'PRIMARY';
160+
$indexes[$row['key_name']]['columns'][$row['seq_in_index'] - 1] = $row['column_name'];
159161
}
160162
return array_values($indexes);
161163
}
@@ -168,10 +170,11 @@ public function getForeignKeys(string $table): array
168170
. 'WHERE TABLE_SCHEMA = DATABASE() AND REFERENCED_TABLE_NAME IS NOT NULL AND TABLE_NAME = ' . $this->connection->quote($table);
169171

170172
foreach ($this->connection->query($query) as $id => $row) {
171-
$keys[$id]['name'] = $row['CONSTRAINT_NAME']; // foreign key name
172-
$keys[$id]['local'] = $row['COLUMN_NAME']; // local columns
173-
$keys[$id]['table'] = $row['REFERENCED_TABLE_NAME']; // referenced table
174-
$keys[$id]['foreign'] = $row['REFERENCED_COLUMN_NAME']; // referenced columns
173+
$row = array_change_key_case((array) $row, CASE_LOWER);
174+
$keys[$id]['name'] = $row['constraint_name']; // foreign key name
175+
$keys[$id]['local'] = $row['column_name']; // local columns
176+
$keys[$id]['table'] = $row['referenced_table_name']; // referenced table
177+
$keys[$id]['foreign'] = $row['referenced_column_name']; // referenced columns
175178
}
176179

177180
return array_values($keys);

0 commit comments

Comments
 (0)