Source for file insert_id.php

Documentation is available at insert_id.php

  1. <?php
  2. /**
  3. * GetInsertID Example
  4. *
  5. * This example uses the GetInsertID method to get the ID of the last inserted AUTO_INCREMENT record.
  6. * @package AbstractDB
  7. * @author Pacific-Cybersoft
  8. * @copyright (C) 2005 Pacific-Cybersoft. All Rights Reserved.
  9. * @version v 1.0.2
  10. * @license http://www.gnu.org/copyleft/lesser.txt GNU Lesser General Public License
  11. */
  12.  
  13. /**
  14. * Include the AbstractDB main class.
  15. */
  16. include("../abstractdb.class.php");
  17.  
  18. // Instatiate AbstractDB
  19. $db = new AbstractDB(array("ConnectionString"=>"mysql://username:password@localhost/mydatabase"));
  20. // Execute a Query
  21. if($db->Query("INSERT tablename (field1, field2) VALUES ('field1', 'field2')"))
  22. {
  23. // Get the insert ID
  24. $inserID = $db->GetInsertID();
  25. }
  26. else
  27. {
  28. die($db->GetLastError());
  29. }
  30. // Always good practice to close AbstractDB at the end of each script.
  31. $db->Close();
  32. ?>

Documentation generated on Wed, 16 Mar 2005 23:17:24 +1100 by phpDocumentor 1.3.0RC3