RE: [PHP-WIN] SQL SELECT while INSERTING
| From: | Asendorf, John | Date: | Thu, 07 Dec 2000 13:57:02 +0000 |
| Subject: | RE: [PHP-WIN] SQL SELECT while INSERTING | ||
| Groups: | php.windows | ||
| Request: | Send a blank email to php-windows+get-4349@lists.php.net to get a copy of this message | ||
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
>
>
>