Php getColumnMeta未返回正确的字段类型
我有一个innodb表,运行MySQL 5.5,方案如下:Php getColumnMeta未返回正确的字段类型,php,pdo,Php,Pdo,我有一个innodb表,运行MySQL 5.5,方案如下: `id` int(10) unsigned NOT NULL AUTO_INCREMENT, `category_id` int(10) unsigned DEFAULT NULL, `uuid` varchar(36) NOT NULL, 我试图使用获取id列类型,但它提供了错误的数据: array(3) { [0]=> array(7) { ["native_type"]=> string(4)
`id` int(10) unsigned NOT NULL AUTO_INCREMENT,
`category_id` int(10) unsigned DEFAULT NULL,
`uuid` varchar(36) NOT NULL,
我试图使用获取id
列类型,但它提供了错误的数据:
array(3) {
[0]=>
array(7) {
["native_type"]=>
string(4) "LONG"
["flags"]=>
array(2) {
[0]=>
string(8) "not_null"
[1]=>
string(11) "primary_key"
}
["table"]=>
string(7) "entries"
["name"]=>
string(2) "id"
["len"]=>
int(10)
["precision"]=>
int(0)
["pdo_type"]=>
int(2)
}
[1]=>
array(7) {
["native_type"]=>
string(4) "LONG"
["flags"]=>
array(1) {
[0]=>
string(12) "multiple_key"
}
["table"]=>
string(7) "entries"
["name"]=>
string(11) "category_id"
["len"]=>
int(10)
["precision"]=>
int(0)
["pdo_type"]=>
int(2)
}
[2]=>
array(7) {
["native_type"]=>
string(10) "VAR_STRING"
["flags"]=>
array(1) {
[0]=>
string(8) "not_null"
}
["table"]=>
string(7) "entries"
["name"]=>
string(4) "uuid"
["len"]=>
int(108)
["precision"]=>
int(0)
["pdo_type"]=>
int(2)
}
}
请求的PHP代码:
$select = $db
->query("
SELECT
`id`,
`category_id`,
`uuid`
FROM
`entries`
LIMIT 1;
;
");
$meta = [];
for($i = 0, $j = $select->columnCount(); $i < $j; $i++)
{
$meta[] = $select->getColumnMeta($i);
}
$select=$db
->查询(”
挑选
`id`,
`类别_id`,
`uuid`
从…起
`条目`
限值1;
;
");
$meta=[];
对于($i=0,$j=$select->columnCount();$i<$j;$i++)
{
$meta[]=$select->getColumnMeta($i);
}
我不会使用此函数来确定列的类型。文件上说这是实验性的,体操根本不值得。我将使用:
SHOW COLUMNS FROM [table]
这将为您提供结果中的纯MySQL类型。有点不太优雅。但是要可靠得多。你能展示一下你的php代码吗?我一定是遗漏了什么。怎么了?您不希望unsigned进入PHP类型,是吗?好吧,我如何告诉您给定的信息列是
INT
?LONG与INT相同。