<< previous page   --   table of contents   --   next page >>
| | | | | | | |
  • Return to Table of Contents
  • Table of Contents

    1. General Information
    2. MySQL Installation
    3. Tutorial Introduction
    4. Database Administration
    5. MySQL Optimisation
    6. MySQL Language Reference
    7. MySQL Table Types
    8. MySQL APIs
    9. Extending MySQL

    Chapter 8:  MySQL APIs 603    mysql_insert_id() returns the ID generated by the last query that inserted a row into a  table  with  an  AUTO_INCREMENT  index.   See  Section  8.4.3.30  [mysql_insert_id()], page 580.    Some  queries  (LOAD DATA INFILE ...,  INSERT INTO ... SELECT ...,  UPDATE)  return additional information.  The result is returned by mysql_info().  See the description for mysql_info() for the format of the string that it returns.  mysql_info() returns a NULL pointer if there is no additional information. 8.4.6.3  How Can I Get the Unique ID for the Last Inserted Row? If you insert a record in a table containing a column that has the AUTO_INCREMENT attribute, you can get the most recently generated ID by calling the mysql_insert_id() function. You can  also  retrieve  the  ID  by using  the  LAST_INSERT_ID()  function in  a  query string that you pass to mysql_query(). You can check if an AUTO_INCREMENT index is used by executing the following code.  This also checks if the query was an INSERT with an AUTO_INCREMENT index: if (mysql_error(&mysql)[0] == 0 && mysql_num_fields(result) == 0 && mysql_insert_id(&mysql) != 0) { used_id = mysql_insert_id(&mysql); } The most recently generated ID is maintained in the server on a per-connection basis.  It will not be changed by another client.  It will not even be changed if you update another AUTO_INCREMENT  column with a non-magic value (that is, a value that is not  NULL  and not 0). If you want to use the ID that was generated for one table and insert it into a second table, you can use SQL statements like this: INSERT INTO foo (auto,text) VALUES(NULL,'text'); # generate ID by inserting NULL INSERT INTO foo2 (id,text) VALUES(LAST_INSERT_ID(),'text');   # use ID in second table 8.4.6.4  Problems Linking with the C API When linking with the C API, the following errors may occur on some systems: gcc -g -o client test.o -L/usr/local/lib/mysql -lmysqlclient -lsocket - Undefined first referenced symbol in file floor /usr/local/lib/mysql/libmysqlclient.a(password.o) ld: fatal: Symbol referencing errors. No output written to client If this happens on your system, you must include the math library by adding -lm to the end of the compile/link line.
     

    Customer Support CentreMySQL Reference Manual

    Web Hosting Services
    UNIX WEB HOSTING
    MERCHANT ACCOUNTS
    DEDICATED SERVERS
    E-COMMERCE HOSTING
    SUPPORT & FAQ's
    TERMS OF USE
    Domain Services
    DOMAIN
    REGISTRATION
    MANAGE
    YOUR ACCOUNT
    SUPPORT & FAQ's
    TERMS OF USE
    Corporate Info
    ABOUT US
    OUR NETWORK
    CONTACT US
    SITE MAP
    Copyright © 2002 Dyntex Group, Inc. All Rights Reserved
  • Return to Table of Contents
  • Back to top

  • Web Hosting: Manuals & FAQ's

    1. Unix-Based Web Hosting
    2. Unix Dedicated Servers
    3. Windows Dedicated Servers
    4. CuteFTP User’s Guide
    5. CuteHTML User’s Guide
    6. WS_FTP Pro User's Guide
    7. Miva Order User's Guide
    8. Miva Merchant User's Guide