insert()方法的返回值是零的問題,大神們我想請教一下
用mysqli_insert_id(connect())時的返回值一只是0,而用$link=connect(),mysqli_insert_id($link)時返回值正常,我可以認為這個函數的參數只能是一個變量而不能是一個方法嗎?
用mysqli_insert_id(connect())時的返回值一只是0,而用$link=connect(),mysqli_insert_id($link)時返回值正常,我可以認為這個函數的參數只能是一個變量而不能是一個方法嗎?
2016-09-04
舉報
2017-04-17
是這樣的,mysqli_insert_id(connect()),returns the ID generated by a query on a table with a column having the AUTO_INCREMENT attribute. If the last query wasn't an?INSERT?or?UPDATE?statement or if the modified table does not have a column with the?AUTO_INCREMENT?attribute, this function?will return zero.
?也就是說,如果最后一句sql不是插入或者是update,返回值為0,我的建議是把insert方法的最后兩行變成:
$result=mysqli_query(connect(),$sql);
return $result;
mysqli_query()函數如果是插入操作成功,那么返回值為true;
2016-11-18
可以一起討論一下。
2016-09-28
因為你插入的那個表沒有自增長字段(mysqli_insert_id返回的id)就返回0;