Phorum.ro
Your Avatar Welcome to Phorum.ro!
If you haven't registered yet, click here!
Attention Visitor:
You may have to register before you can post: click the register link above to proceed. To start viewing messages, select the forum that you want to visit from the selection below.
Du-te înapoi   Phorum.ro > Web Design & Web Development > Programare > PHP > PHP DB

PHP DB Discutii despre lucrul cu baze de date in PHP.

Răspunde
 
Thread Tools Moduri de afișare
Vechi 17.05.2007   #1
Chip
16-Bit Member
 
Data înregistrării: 12.09.2005
Mesaje: 17
Rep Power: 7
Chip is on a distinguished road
Implicit valuare auto_increment returnata

am o valoare automata (unique, auto_increment) care retine un id. vreau ca imediat dupa inserare sa obtin ce numar s-a pus automat in campul id, fara sa mai fac un query de select (pana acum asa faceam, imediat dupa inserare faceam un query select sa citesc idul unde erau restul datelor la fel ca la inserare). cum fac asta?
Chip is offline   Reply With Quote
Sponsored Links
Vechi 18.05.2007   #2
Zeon
32-Bit Member
 
Data înregistrării: 10.05.2006
Mesaje: 167
Rep Power: 7
Zeon is on a distinguished road
Implicit

$result = mysql_query("INSERT INTO ... ");
$lastid = mysql_insert_id();

Citat:
În prealabil postat de php.net
Caution

mysql_insert_id() converts the return type of the native MySQL C API function mysql_insert_id() to a type of long (named int in PHP). If your AUTO_INCREMENT column has a column type of BIGINT, the value returned by mysql_insert_id() will be incorrect. Instead, use the internal MySQL SQL function LAST_INSERT_ID() in an SQL query.
$result = mysql_query("INSERT ...");
$result = mysql_query("SELECT LAST_INSERT_ID() as lastid");
$row = mysql_fetch_assoc($result);
echo $row['lastid'];

bafta.
Zeon is offline   Reply With Quote
Răspunde


Currently Active Users Viewing This Thread: 1 (0 members and 1 guests)
 
Thread Tools
Moduri de afișare

Reguli de postare
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 Pornit
emoticoanele sunt Pornit
Codul [IMG] este Pornit
Codul HTML este Oprit



Ora este GMT +3. Ora este acum 02:49:18.


Rulează cu: vBulletin Version 3.8.4
Copyright ©2000 - 2012, Jelsoft Enterprises Ltd.
Forum SEO by Zoints

XXXXXXXXXXXXXXXXXXX
Inactive Reminders By Icora Web Design