我不确定此函数在实现中有多有用。以这个例子为例
CREATE TABLE `blah` (
`x` varchar(100) NOT NULL,
`y` varchar(100) NOT NULL,
`z` varchar(100) NOT NULL
) ENGINE=InnoDB DEFAULT CHARSET=latin1;
INSERT INTO blah SET z = '1';
Query OK, 1 row affected, 2 warnings (0.00 sec)
mysql> show warnings;
+---------+------+----------------------------------------+
| Level | Code | Message |
+---------+------+----------------------------------------+
| Warning | 1364 | Field 'x' doesn't have a default value |
| Warning | 1364 | Field 'y' doesn't have a default value |
+---------+------+----------------------------------------+
从 PHP 中使用 mysqli_get_warnings() 执行相同的操作,您将获得以下结果
object(mysqli_warning)#4 (3) {
["message"]=>
string(38) "Field 'x' doesn't have a default value"
["sqlstate"]=>
string(5) "HY000"
["errno"]=>
int(1364)
}
即它只返回第一个警告。我怀疑它应该返回这些对象的数组,而不仅仅是一个。至少您现在知道返回值是什么样子,因为文档中没有说明!