在fetchAll命令之后,我返回了以下数组
Array ( [0] => Array ( [Name] => tbl_events [0] => tbl_events [Engine] => MyISAM
[1] => MyISAM [Version] => 10 [2] => 10 [Row_format] => Dynamic [3] => Dynamic
[Rows] => 9 [4] => 9 [Avg_row_length] => 214 [5] => 214 [Data_length] => 2148
[6] => 2148 [Max_data_length] => 281474976710655 [7] => 281474976710655
[Index_length] => 2048 [8] => 2048 [Data_free] => 216 [9] => 216
[Auto_increment] => 1420 [10] => 1420 [Create_time] => 2019-10-08 15:21:32
[11] => 2019-10-08 15:21:32 [Update_time] => 2019-10-23 19:00:02
[12] => 2019-10-23 19:00:02 [Check_time] =>
[13] => [Collation] => latin1_swedish_ci [14] => latin1_swedish_ci [Checksum] =>
[15] => [Create_options] => [16] => [Comment] => [17] => ) )
我正在尝试获取Auto_increment的值,并将其分配给变量$ newID
我正在使用的代码是
$sqlNEWID = "SHOW TABLE STATUS LIKE 'tbl_events'";
$stmt = $conn->prepare($sqlNEWID);
$stmt->execute();
$newID_data = $stmt->fetchAll();
print_r($newID_data);
$newID = $newID_data['Auto_increment'];
但是那什么都不返回,我猜是因为数组是数组中的一个数组还是一系列数组?
有人能启发我吗?
答案 0 :(得分:0)
我通过替换获得了理想的结果
$newID_data = $stmt->fetchAll();
使用
$newID_data = $stmt->fetch(PDO::FETCH_ASSOC);
问题解决了!