-
Notifications
You must be signed in to change notification settings - Fork 267
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Insert_ID is not working when using mysqli #166
Comments
Is this issue reproducable In 5.19? |
Yes , same thing. Just in case, I am using |
I just noticed something with mysql (debug on) (mysql): CALL sp_insert_taxid(224,'482',1,'23744','') with mysqli The LAST_INSERT_ID is just NOT EXECUTED using mysqli internally |
I am also running on a bsd server, and the same thing happens |
Just wanted to make sure this was not a regression error with the new release |
Is the first time for me using mysqli. I never had any problems with the mysql extension. But now that is being deprecated, more people will move to mysqli |
I use LAST_INSERT_ID ALL the time. If it is a bug , I am very surprise. I will think it is used a lot. |
This is what I think is the problem: There is a method in each driver called in _insertid(). The one in the mysql driver executes 'SELECT LAST_INSERT_ID', whilst the mysqli driver uses the driver function mysqli_insert_id(). It's possible that the second one does not work correctly with stored procedures, or needs further configuration. As the mysqli driver extends the mysql driver, you could easily test this by renaming the method in the mysqli driver (adodb/drivers/adodb-mysqli.inc.php) and seeing if that fixes the problem. Looking at the code in the mysql driver, it looks like an attempt to use mysql_insert_id() there has been abandoned. |
The issue is as I thought, replacing the call to There is a bigger problem, however, as the statement is not actually being prepared by the call. It is being handled in the ADOdb compatibility mode, i.e the call to $sql = "CALL sp_test(?,?,?)";
$datamap = array($p1, $p2, $p3);
$rs = $cn->Execute($sql,$datamap); So you are not actually receiving any of the benefits of SP preparation, (Nor were you in the original driver). I'm not sure what it would take to implement this correctly, @dregad , perhaps you know mysql stored procedures better than I? [updated] |
What is your suggestion? Is it better to keep using the mysql extension? |
@mnewnham Just to clarify in terms of roadmap, I see you qualify this as "hotfix", does this mean you think it should be targeted at 5.20.2, or is it just a regular bugfix that goes in next release (5.21) ? I would say the latter, since the issue was already present in 5.19.
Probably not, I hardly ever use them ;-) |
@stccorp , no you should use the hotfix and migrate your applications |
Please see my note in bfd0e0a#commitcomment-14988787 - the commit introduces dead code. |
From the documentation that you linked:
Suggestions
|
Please dont go with option 1. I have been using adodb for more than 7 years. One of the things I like is the ability to switch databases with just the connection string. If you use option 1, it will mean that people have to go through the code to see if they are using a store procedure or not. For large applications, it is just not practical. Option 4 or 5 seems more practical and 0 impact to the programmer |
Can anyone shine a light on this statement in the documentation:
What 'exact information' can be provided that we would care about? |
I agree that if we can provide a way to retrieve the last insert ID, then we should do it. It has to be clear however, that we may not be able to cover all cases depending on what the stored procedure does.
From http://dev.mysql.com/doc/refman/5.7/en/mysql-insert-id.html :
The key here is point 2:
This is the reason why I was suggesting to use a hybrid approach (first try mysqli_insert_id() and fallback to last_insert_id() if we get 0). One more thing about the
|
Note from @mnewnham over chat:
No, see my note #166 (comment) Regarding the loop scenario, I guess it's possible. In that case, maybe we can circumvent that by checking for an error prior to doing the fallback (didn't test) |
I've rethought this and I believe the following simplifies the procedure.
|
Sounds OK to me. |
When using prepared statements, the last insert id was not retrieved correctly. New feature optimally uses the suggested mysql method for obtaining the value based on whether it was generated by a prepared statement or not.
When using prepared statements, the last insert id was not retrieved correctly. New feature optimally uses the suggested mysql method for obtaining the value based on whether it was generated by a prepared statement or not.
For mysqli and adodb this simple function should work: |
I just upgraded to php 5.5.30 and I am using the latest adodb 520. When I use mysqli, my id is always 0. When I use mysql I get the expected id. Is it not supported in mysqli? Is it a bug? Thank you
$cn = ADONewConnection('mysqli');
$cn->SetFetchMode(ADODB_FETCH_ASSOC);
$sql = "CALL sp_test(?,?,?)";
$stmt = $cn->Prepare($sql);
$datamap = array($p1, $p2, $p3);
$rs = $cn->Execute($stmt,$datamap);
$id= $cn->Insert_ID(); //************* ERROR wih 0 when using mysqli
The text was updated successfully, but these errors were encountered: