Reputation: 442
I have this problem:
I do query, no error, data writed to the DB.
When i try to get the "insert_id" no data returned... but if i do "echo" function, write the value.
Code:
$insert_id = (int)$this -> conn -> insert_id;
echo '#'.$this -> conn -> insert_id.'#';
print_r($this -> conn);
die($insert_id);
Result:
#12#
mysqli Object
(
[affected_rows] => 1
...
[connect_errno] => 0
[connect_error] =>
[errno] => 0
[error] =>
[field_count] => 0
...
[info] =>
[insert_id] => 12
...
)
Why i cant get the ID from "$insert_id = (int)$this -> conn -> insert_id;" this!?
Thanks!
Upvotes: 0
Views: 479
Reputation: 390
Try mysqli_insert_id()
- $conn->insert_id
Manual: http://www.php.net/manual/en/mysqli.insert-id.php
Upvotes: -1
Reputation: 157917
That's indeed a funny question.
You need to read die()'s manual page to get your answer:
status
If status is a string, this function prints the status just before exiting.If status is an integer, that value will be used as the exit status and not printed. Exit statuses should be in the range 0 to 254, the exit status 255 is reserved by PHP and shall not be used. The status 0 is used to terminate the program successfully.
Upvotes: 3