Re: Re: the Pear::DB way to do mysql_insert_id?

From: Date: Fri, 03 Jan 2003 12:11:29 +0000
Subject: Re: Re: the Pear::DB way to do mysql_insert_id?
References: 1 2  Groups: php.pear.general 
Request: Send a blank email to pear-general+get-3164@lists.php.net to get a copy of this message
On Fri, 3 Jan 2003 08:58:46 +1100 "electroteque" <daniel@electroteque.org> wrote: > i added this function to mysql.php > > function lastinsertId() > { > $result = @mysql_insert_id($this->connection); > return $result; > } > > i have no need for sequences i use auto inc rows That´s your decision, but note two things: 1. Your code will never work with databases that support only sequences, _not_ autoincrement fields (like PostgreSQL, Oracle and the like). Therefore, using PEAR::DB will only make sense if you plan on supporting i.e. MSSQL and Access alongside MySQL. If all you ever want is MySQL, you´re better off using the native MySQL functions, as these are way faster than using PEAR::DB and you don´t have a real need for abstraction after all. 2. If you want to add your own functionality to PEAR::DB it´s better to make your own driver class, which can be as simple as this: require_once('DB/mysql.php'); class myMysql extends mysql { function lastinsertId() { $result = @mysql_insert_id($this->connection); return $result; } } Save this to a file "myMysql.php" in the DB directory. You can now use "myMysql" in the DSN to connect to MySQL using your own driver. The advantage of this: When you upgrade to a newer version of DB, you won´t need to redo all your custom changes to it, as all your class automatically inherits all changes to the base package. Regards, Markus -- Markus Wolff <wolff@21st.de>

« previous php.pear.general (#3164) next »