Error using mysql_insert_id( ) - call to undefined function

PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!

Moderator: General Moderators

Post Reply
mcccy005
Forum Contributor
Posts: 123
Joined: Sun May 28, 2006 7:08 pm

Error using mysql_insert_id( ) - call to undefined function

Post by mcccy005 »

I get this error when trying to use the mysql_insert_id( ) function:
Fatal error: Call to undefined function mysql_insert_id() in D:\\XXXXX\abc.php on line 127

Ok.....so in the php.ini file; yes i have extension=php_mysql.dll commented out using ";". BUT...when I uncomment this, I get the following error:
PHP Warning: PHP Startup: Unable to load dynamic library './php_mysql.dll' - The specified module could not be found. in Unknown on line 0


THEN....if I use the mysqli function: $id=$db_connection->insert_id( ), I get the following error:
Fatal error: Call to undefined method mysqli::insert_id() in D:\Splash_Solutions\Web_Pages\hb_info.php on line 127

(This has been asked by me in a seperate unrelated thread (something about php redirect) so please ignore the question in that thread. Cheers.
User avatar
ambivalent
Forum Contributor
Posts: 173
Joined: Thu Apr 14, 2005 8:58 pm
Location: Toronto, ON

Post by ambivalent »

I believe your issue is addressed in the manual. Specifically, the installation notes.
bdlang
Forum Contributor
Posts: 395
Joined: Tue May 16, 2006 8:46 pm
Location: Ventura, CA US

Post by bdlang »

In your php.ini file, make sure you uncomment the line marked 'extension=php_mysql.dll' (as you mentioned), as well as create a line 'extension=php_mysqli.dll'.

More importantly, make sure the extension_dir directive points to the actual extensions directory in your php install, e.g. 'c:/php/ext'

Code: Select all

extension_dir=C:/php/ext    ; or wherever you've installed php

; uncomment / create these lines
extension=php_mysql.dll
extension=php_mysqli.dll
Restart your HTTPD server (Apache, most likely) and test it out.
mcccy005
Forum Contributor
Posts: 123
Joined: Sun May 28, 2006 7:08 pm

Post by mcccy005 »

sorry - forgot to mention that I'm already using mysqli, so that already is uncommented; so that suggestion doesnt work either.
For the record, I'm actually using MS IIS 4 (havent had any luck using apache), although it probably makes little difference.
User avatar
RobertGonzalez
Site Administrator
Posts: 14293
Joined: Tue Sep 09, 2003 6:04 pm
Location: Fremont, CA, USA

Post by RobertGonzalez »

Do you have the php_mysql.dll file in your PHP extensions dir?
mcccy005
Forum Contributor
Posts: 123
Joined: Sun May 28, 2006 7:08 pm

Post by mcccy005 »

in the directory that i originally installed php i have the following:
php5ts.dll;
libmysql.dll and;
php_mysqli.dll;
(plus of course a few empty folders and a few *.txt files and the *.exe file).

libmysql.dll and php_mysqli.dll are the things I got form either the php or mysql website which was supposed to fix all of the errors i seem to continuously encounter.

If I need this php_mysql.dll file where can I find it??
And do I simply put it into the same folder as the above *.dll files and uncomment it in the php.ini file??

Appreciate your help. Thanks
bdlang
Forum Contributor
Posts: 395
Joined: Tue May 16, 2006 8:46 pm
Location: Ventura, CA US

Post by bdlang »

You don't have an 'ext' subdirectory? I'd be carefull downloading and arbitrarily sticking .dll files in your PHP install directory. What installation method did you choose?

This is how I install PHP5 under Windows..
  • Download the .zip package
  • Unzip to C:\php5
  • Add C:\php5 to the PATH (see Google for 'set Windows PATH')
  • Copy the C:\php5\php.ini-recommended file to C:\php5\php.ini
  • Edit the php.ini file:

    Code: Select all

    ;; extension directives
    extension_dir="C:/php5/ext"
    extension=php_mysql.dll
    extension=php_mysqli.dll
    ;; find other 'Windows' directives and set properly
  • Configure your HTTPD installation, if necessary, and restart
I only have PHP installed as CLI on my Windows machines, so I won't detail the process any further, but those simple steps gets me up and running in a few minutes.
User avatar
RobertGonzalez
Site Administrator
Posts: 14293
Joined: Tue Sep 09, 2003 6:04 pm
Location: Fremont, CA, USA

Post by RobertGonzalez »

mcccy005 wrote:in the directory that i originally installed php i have the following:
php5ts.dll;
libmysql.dll and;
php_mysqli.dll;
(plus of course a few empty folders and a few *.txt files and the *.exe file).

libmysql.dll and php_mysqli.dll are the things I got form either the php or mysql website which was supposed to fix all of the errors i seem to continuously encounter.

If I need this php_mysql.dll file where can I find it??
And do I simply put it into the same folder as the above *.dll files and uncomment it in the php.ini file??

Appreciate your help. Thanks
If you don't have php_mysql.dll then you cannot use the mysql_* functions. But it appears that you have the php_mysqli.dll, so I would use the mysqli_* functions instead. They are very similar to the mysql_* functions, but you have the option of using an object oriented approach as well.

The mysqli functions and a description of them can be found in the PHP Manual section on MySQLi.
mcccy005
Forum Contributor
Posts: 123
Joined: Sun May 28, 2006 7:08 pm

Post by mcccy005 »

hmm....for some strange reason; I've just mucked around with what you guys have said but haven't actually modified anything and now its all of a sudden working!!!
Guess if it 'aint broke, dont fix it'....thanks again.

One quick thing though....is it worth my while attemptint to install the mysql stuff or just stick with mysqli or is there some things the original mysql has that hasn't yet been implemmented into mysqli??
Cheers.
printf
Forum Contributor
Posts: 173
Joined: Wed Jan 12, 2005 5:24 pm

Post by printf »

both work good, but in my testing I have found mysql is always faster than mysqli in straight query performance. But the added features in mysqli makes it nice, ya no more mysql_real_escape_string(). But to spend time converting code that works fine in mysql to get the added features is not really worth it for all cases. But if you have base class structure, then adding mysqli is very simple. I use mysqli for some projects where I need to use more of MySQL features, like triggers and prepared statements, when you use those features correctly you free up resources and make your whole application much faster, because you don't have to use direct execution, where MySQL has to rebuild the query every time you run it. But like I said, mysql is still much faster when doing a straight query, including JOINS, UNIONS, REGEXP and FULL TEXT searching as compared to mysqli!

pif!
User avatar
RobertGonzalez
Site Administrator
Posts: 14293
Joined: Tue Sep 09, 2003 6:04 pm
Location: Fremont, CA, USA

Post by RobertGonzalez »

mcccy005 wrote:hmm....for some strange reason; I've just mucked around with what you guys have said but haven't actually modified anything and now its all of a sudden working!!!
Guess if it 'aint broke, dont fix it'....thanks again.

One quick thing though....is it worth my while attemptint to install the mysql stuff or just stick with mysqli or is there some things the original mysql has that hasn't yet been implemmented into mysqli??
Cheers.
There's no reason why you can't use both. mysqli is kinda the format of the future, offering both built-in OOP functionality and procedural flexibility. And I believe for PHP6 the speed/resource issues are going to be resolved. But either way, they both work fine. Right now if your apps are designed using a procedural style mysql_* interaction, I would load the php_mysql.dll and use that rather recoding your app. I would, however, seriously look into DB abstraction or the use of a DB class interface so in the future, if you are facing something like this, it will be as easy as changing an included file when it comes to getting the app back online.
Post Reply