Edit report at http://bugs.php.net/bug.php?id=54142&edit=1

 ID:                 54142
 Updated by:         dtajchre...@php.net
 Reported by:        lissetteganoza at gmail dot com
 Summary:            the function  mysqli_insert_id doesn't return the
                     last id
-Status:             Open
+Status:             Bogus
 Type:               Bug
 Package:            PHP options/info functions
 Operating System:   windows
 PHP Version:        5.2.17
 Block user comment: N
 Private report:     N

 New Comment:

david@copenhagen:~/test$ mysql -u root -p

Enter password: 

Welcome to the MySQL monitor.  Commands end with ; or \g.

Your MySQL connection id is 64

Server version: 5.1.41-3ubuntu12.10 (Ubuntu)



Type 'help;' or '\h' for help. Type '\c' to clear the current input
statement.



mysql> use test;

Reading table information for completion of table and column names

You can turn off this feature to get a quicker startup with -A



Database changed

mysql> describe test;

+-------+------------------+------+-----+---------+----------------+

| Field | Type             | Null | Key | Default | Extra          |

+-------+------------------+------+-----+---------+----------------+

| pid   | int(10) unsigned | NO   | PRI | NULL    | auto_increment |

| n_pid | date             | NO   |     | NULL    |                |

+-------+------------------+------+-----+---------+----------------+

2 rows in set (0.00 sec)



mysql> select * from test;

+-----+------------+

| pid | n_pid      |

+-----+------------+

|   1 | 2011-03-02 |

+-----+------------+

1 row in set (0.00 sec)



mysql> exit

Bye

david@copenhagen:~/test$ cat t.php 

<?php



$l = mysqli_connect('127.0.0.1', 'root', 'root');

var_dump(mysqli_select_db($l, 'test'));

var_dump(mysqli_query($l, 'insert into test (n_pid)
values(curdate())'));

var_dump(mysqli_insert_id($l));



david@copenhagen:~/test$ /home/david/dev/php/php53/sapi/cli/php -v

PHP 5.3.6-dev (cli) (built: Feb 26 2011 23:29:38) (DEBUG)

Copyright (c) 1997-2011 The PHP Group

Zend Engine v2.3.0, Copyright (c) 1998-2011 Zend Technologies

david@copenhagen:~/test$ /home/david/dev/php/php53/sapi/cli/php t.php 

bool(true)

bool(true)

int(9)

david@copenhagen:~/test$ mysql -u root -p

Enter password: 

Welcome to the MySQL monitor.  Commands end with ; or \g.

Your MySQL connection id is 66

Server version: 5.1.41-3ubuntu12.10 (Ubuntu)



Type 'help;' or '\h' for help. Type '\c' to clear the current input
statement.



mysql> use test;

Reading table information for completion of table and column names

You can turn off this feature to get a quicker startup with -A



Database changed

mysql> select * from test;

+-----+------------+

| pid | n_pid      |

+-----+------------+

|   1 | 2011-03-02 |

|   9 | 2011-03-02 |

+-----+------------+

2 rows in set (0.00 sec)



mysql> exit

Bye

david@copenhagen:~/test$


Previous Comments:
------------------------------------------------------------------------
[2011-03-02 22:42:17] lissetteganoza at gmail dot com

Description:
------------
---

>From manual page: http://www.php.net/mysqli.insert-id#Descripción

---



The function mysqli_insert_id  does not return the if of the last
insert. The 

query was executed without problem but I can get the id of this insert.
I want to 

konw if exist other function other possiblity, maybe I need to
reconfigure some 

value in the php ini, but I need a solution and this solution must be in
the 

documents of this funcionality.

I'm adding the function that I have for insert a row.

 

Test script:
---------------
function insert($ins)

        {

                $result = @mysqli_query($this->conn,$ins);



                if (!$result)

                {

                        $this->writeTemplate(DB_TITULO_ERROR,mysqli_error());

                }



                return @mysqli_insert_id($this->conn);

        }

Expected result:
----------------
- A solution to use correctly this function

- Id does not exist a solution with this function, another solution with
other 

functions of mysql

Actual result:
--------------
the function returns a empty object.


------------------------------------------------------------------------



-- 
Edit this bug report at http://bugs.php.net/bug.php?id=54142&edit=1

Reply via email to