|
php.net | support | documentation | report a bug | advanced search | search howto | statistics | random bug | login |
[2000-12-04 14:23 UTC] tetherow at nol dot org
MySQL insert_id function returns 0 on valid insert.
Using PHP 4.0.3pl1 and MySQL 3.23.28gamma.
configured using --with-mysql=/usr/local
$connection=mysql_pconnect($server, $username, $password);
$cursor=mysql_db_query('staff', $query, $connection);
$id=mysql_insert_id();
have also tried
$id=mysql_insert_id($connection)
In both instances $id is 0 yet the insert does succeed.
PatchesPull RequestsHistoryAllCommentsChangesGit/SVN commits
|
|||||||||||||||||||||||||||
Copyright © 2001-2025 The PHP GroupAll rights reserved. |
Last updated: Tue Oct 28 01:00:01 2025 UTC |
mysql> show columns from staff; +-----------+--------------+------+-----+---------+----------------+ | Field | Type | Null | Key | Default | Extra | +-----------+--------------+------+-----+---------+----------------+ | id | int(11) | | PRI | NULL | auto_increment | | firstname | varchar(80) | YES | | NULL | | | lastname | varchar(80) | YES | | NULL | | | title | varchar(80) | YES | | NULL | | | phone | varchar(15) | YES | | NULL | | | cell | varchar(15) | YES | | NULL | | | home | varchar(15) | YES | | NULL | | | pager | varchar(60) | YES | | NULL | | | email | varchar(30) | YES | | NULL | | | username | varchar(16) | YES | | NULL | | | password | varchar(16) | YES | | NULL | | | epassword | varchar(16) | YES | | NULL | | | company | int(11) | YES | | NULL | | | role | varchar(80) | YES | | NULL | | | other | varchar(15) | YES | | NULL | | | active | tinyint(4) | YES | | NULL | | | shell | varchar(128) | YES | | NULL | | | forward | varchar(64) | YES | | NULL | | | disporder | int(11) | YES | | NULL | | +-----------+--------------+------+-----+---------+----------------+ $query="insert into staff (id, firstname, lastname, title, phone, cell, home, pager, email, username, password, epassword, company, role, other, active, shell, forward, disporder) values (NULL, '$this->firstname', '$this->lastname', '$this->title', '$this->phone', '$this->cell', '$this->home', '$this->pager', '$this->email', '$this->username', '$this->password', '$this->epassword', '$this->company', '$this->role', '$this->other', '1', '$this->shell', '', $this->disporder)"; $cursor=mysql_db_query('staff', $query, $connection); // Need to check return here. $this->id=mysql_insert_id($connection); echo "Connection: $connection<br>\nID: $this->id<br>\n"; When run $connection is set to a valid resource and $this->id is 0. The data does get inserted into the database without any problems so I know the query is good. I looked at the page referenced and the auto_increment field is a standard int field. The LAST_INSERT_ID() function appears to work but am curious as to why the mysql_insert_id does not.