AW: [PHP-WIN] SQL SELECT while INSERTING
| From: | Michael Rudel | Date: | Thu, 07 Dec 2000 08:41:38 +0000 |
| Subject: | AW: [PHP-WIN] SQL SELECT while INSERTING | ||
| Groups: | php.windows | ||
| Request: | Send a blank email to php-windows+get-4344@lists.php.net to get a copy of this message | ||
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