Delphi For PHP Forums       


Go Back   Delphi-PHP Forums > Programming > Database Integration
Forum Jump Register FAQ Members List Downloads Search Today's Posts Mark Forums Read

Database Integration How to use MySql, PostgreSQL, MS SQL, Oracle, and most other databases with PHP.

Reply
 
LinkBack Thread Tools Display Modes
  #1 (permalink)  
Old 14th July 2009, 11:08
D4PHP Engineer
 
Join Date: Jul 2007
Posts: 431
classic is on a distinguished road
Default ID of last inserted record is: 0

function Button5Click($sender, $params)
{
$sql2 = "insert into customers (billaddress_firstname) VALUES ('newone')";
$this->Database1->Execute($sql2);
echo "ID of last inserted record is: " . mysql_insert_id();

}

I have similar code in another app (different database) and the id is returned correctly.

customers table has field 'cid set to auto inc and key field.

Any ideas please?
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
Reply With Quote
Sponsored Links
  #2 (permalink)  
Old 14th July 2009, 11:09
D4PHP Engineer
 
Join Date: Jul 2007
Posts: 431
classic is on a distinguished road
Default

Sorry forgot to mention a new record is inserted into the table
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
Reply With Quote
  #3 (permalink)  
Old 14th July 2009, 11:50
405hp's Avatar
Firebug Fanatic
 
Join Date: Dec 2007
Location: State of Confusion
Posts: 3,272
405hp has a reputation beyond repute405hp has a reputation beyond repute405hp has a reputation beyond repute405hp has a reputation beyond repute405hp has a reputation beyond repute405hp has a reputation beyond repute405hp has a reputation beyond repute405hp has a reputation beyond repute405hp has a reputation beyond repute405hp has a reputation beyond repute405hp has a reputation beyond repute
Default

From the Manual:

Quote:
The ID generated for an AUTO_INCREMENT column by the previous INSERT query on success, 0 if the previous query does not generate an AUTO_INCREMENT value, or FALSE if no MySQL connection was established.
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
Reply With Quote
  #4 (permalink)  
Old 14th July 2009, 12:10
D4PHP Engineer
 
Join Date: Jul 2007
Posts: 431
classic is on a distinguished road
Default

I have 2 datasources in the app. If I remove the one not related to the customer table the ID works fine.

So I presume I need a command to say:
echo "ID of last inserted record is: " . mysql_insert_id() from (DATASOURCE1);

How do I do this please?
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
Reply With Quote
  #5 (permalink)  
Old 14th July 2009, 13:26
405hp's Avatar
Firebug Fanatic
 
Join Date: Dec 2007
Location: State of Confusion
Posts: 3,272
405hp has a reputation beyond repute405hp has a reputation beyond repute405hp has a reputation beyond repute405hp has a reputation beyond repute405hp has a reputation beyond repute405hp has a reputation beyond repute405hp has a reputation beyond repute405hp has a reputation beyond repute405hp has a reputation beyond repute405hp has a reputation beyond repute405hp has a reputation beyond repute
Default

A look in the manual
PHP: mysql_insert_id - Manual
says:
int mysql_insert_id ([ resource $link_identifier ] )
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
Reply With Quote
  #6 (permalink)  
Old 14th July 2009, 15:25
D4PHP Engineer
 
Join Date: Jul 2007
Posts: 431
classic is on a distinguished road
Default

Ok got that. In delphi PHP what is the syntax ?

mysql_insert_id ($this->Database1) fails
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
Reply With Quote
  #7 (permalink)  
Old 14th July 2009, 15:45
405hp's Avatar
Firebug Fanatic
 
Join Date: Dec 2007
Location: State of Confusion
Posts: 3,272
405hp has a reputation beyond repute405hp has a reputation beyond repute405hp has a reputation beyond repute405hp has a reputation beyond repute405hp has a reputation beyond repute405hp has a reputation beyond repute405hp has a reputation beyond repute405hp has a reputation beyond repute405hp has a reputation beyond repute405hp has a reputation beyond repute405hp has a reputation beyond repute
Default

Play around with the options until you find it
probably ->_connection
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
Reply With Quote
  #8 (permalink)  
Old 14th July 2009, 18:01
D4PHP Engineer
 
Join Date: Jul 2007
Posts: 431
classic is on a distinguished road
Default

echo "ID of last inserted record is: " . mysql_insert_id($this->Database2->_connection);

fails error:

Warning: mysql_insert_id(): supplied argument is not a valid MySQL-Link resource in

Anyone know the correct syntax please?
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
Reply With Quote
  #9 (permalink)  
Old 9th February 2010, 00:17
dalyla's Avatar
D4PHP User
 
Join Date: Jul 2009
Location: Mexico
Posts: 65
dalyla is on a distinguished road
Default

well, Just left it in blank, nothing between ()
__________________
My world seems to be shinin'
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
Reply With Quote
Reply


Currently Active Users Viewing This Thread: 1 (0 members and 1 guests)
 
Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On


All times are GMT +1. The time now is 05:37.




Powered by vBulletin® Version 3.7.3
Copyright ©2000 - 2010, Jelsoft Enterprises Ltd.
Search Engine Friendly URLs by vBSEO 3.3.0 ©2009, Crawlability, Inc.
Copyright © 2004 - 2009, G&J Solutions Ltd. All Rights Reserved. terms of use