Re: SQL SELECT while INSERTING

From: Date: Fri, 08 Dec 2000 02:25:17 +0000
Subject: Re: SQL SELECT while INSERTING
References: 1  Groups: php.windows 
Request: Send a blank email to php-windows+get-4369@lists.php.net to get a copy of this message
What happens when another record has been added after the insert, and before the select max?? Mok Lai Chuan e-Consultant Dreamvale.com Pte Ltd 111 North Bridge Road #21-01 Singapore 179098 Tel : (65)584 2576 Fax : (65) 234 2248 ----- Original Message ----- From: "Asendorf, John" <JAsendorf@lcounty.com> To: "Michael Rudel" <Michael.Rudel@in-gmbh.de>; "Php-Windows (E-mail)" <php-windows@lists.php.net> Sent: Thursday, December 07, 2000 9:57 PM Subject: RE: [PHP-WIN] SQL SELECT while INSERTING > That's what I'm looking for SELECT MAX, that should do it! Thanks everyone! > > --------------------- > John Asendorf - jasendorf@lcounty.com > Web Applications Developer > http://www.lcounty.com - NEW FEATURES ADDED DAILY! > Licking County, Ohio, USA > 740-349-3631 > > Vah! Denuone Latine loquebar? Me ineptum. Interdum modo elabitur. > > > > > > > -----Original Message----- > > From: Michael Rudel [mailto:Michael.Rudel@in-gmbh.de] > > Sent: Thursday, December 07, 2000 3:42 AM > > To: 'Asendorf, John'; Php-Windows (E-mail) > > Subject: AW: [PHP-WIN] SQL SELECT while INSERTING > > > > > > Hey John, > > > > here's my code, it works well: > > > > function insert( $str_sql, $file = "", $line = "" ) > > { > > $this->db_exec( $str_sql, $file, $line ); > > > > // $this->free_result(); > > > > // Tabellenname aus dem INSERT-Statement extrahieren > > $table = strstr( $str_sql, "INTO" ); > > $table = substr( $table, 5 ); > > $table = substr( $table, 0, strpos( $table, " " ) ); > > > > // Dummy-Select, da beim INSERT keine Spaltennamen > > zurückgegeben > > werden > > $str_sql = "SELECT * FROM ".$table; > > $this->db_exec( $str_sql, $file, $line ); > > > > // Feldnamen der ersten Spalte ermitteln > > $field_name = odbc_field_name( $this->sql_result, 1 ); > > > > // $this->free_result(); > > > > // SELECTiert den Auto-Inkrement-Wertes der INSERT-Operation > > $str_sql = "SELECT MAX(".$field_name.") FROM ".$table; > > $this->db_exec( $str_sql, $file, $line ); > > > > // Holt den Auto-Inkrement-Wert > > $auto_inc = odbc_result( $this->sql_result, 1 ); > > > > // Gibt den Auto-Inkrement-Wert an die aufrufende > > Funktion zurück > > return ( $auto_inc ); > > } > > > > Sorry, it uses my class, but I think you get the Hack while > > reading, isn't > > it ?? > > > > My own ODBC-Class is attached, so you can experiment if you like. It > > contains > > automatic Error-Handling as well. > > > > If you have Questions about it, ask ... you've got my @ddy > > now. Or perhaps I > > could send you a few examples. > > > > Good Luck and have Fun with it =8) > > > > Greetinx, > > Mike > > (Germany) > > > > P.E.: You could join me to your consortium >8)=) > > > > -----Ursprüngliche Nachricht----- > > Von: Asendorf, John [mailto:JAsendorf@lcounty.com] > > Gesendet: Mittwoch, 6. Dezember 2000 20:42 > > An: Php-Windows (E-mail) > > Betreff: [PHP-WIN] SQL SELECT while INSERTING > > > > > > Hello all, > > > > Have a quick question. Can I select an auto-incrementing key > > at the same > > time I am 'inserting into' a new record... > > > > using Access ODBC > > > > like this > > > > $sql = "INSERT INTO blocked (page,name,email,attempt) VALUES > > ('$page','$name','$email','$attempt') > > > > AND GET THE KEY FROM THIS ENTRY HERE > > > > ;"; > > > > Thanks all, > > > > John > > > > --------------------- > > John Asendorf - jasendorf@lcounty.com > > Web Applications Developer > > http://www.lcounty.com - NEW FEATURES ADDED DAILY! > > Licking County, Ohio, USA > > 740-349-3631 > > > > Vah! Denuone Latine loquebar? Me ineptum. Interdum modo elabitur. > > > > > > > > > > > > -- > > PHP Windows Mailing List (http://www.php.net/) > > To unsubscribe, e-mail: php-windows-unsubscribe@lists.php.net > > For additional commands, e-mail: php-windows-help@lists.php.net > > To contact the list administrators, e-mail: > > php-list-admin@lists.php.net > > > > > > > > -- > PHP Windows Mailing List (http://www.php.net/) > To unsubscribe, e-mail: php-windows-unsubscribe@lists.php.net > For additional commands, e-mail: php-windows-help@lists.php.net > To contact the list administrators, e-mail: php-list-admin@lists.php.net >

« previous php.windows (#4369) next »