Re: Better DB Class MySQL

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



On Feb 9, 2008 7:03 PM, nihilism machine <nihilismmachine@xxxxxxxxx> wrote:

> Looking to really beef up my DB class, any suggestions for functions
> to add that will be more time saving for a web 2.0 app, or ways to
> improve existing methods? thank you everyone in advance.


first of all, as a matter of style, its conventional to capitalize class
names.  so
you would change the name to Db.  also, conventionally, member functions are
not capitalized; so Terminator(), becomes terminator().

next thing is you have no escaping of the queries.  you should be wrapping
the
$sql that gets passed into your query method in mysql_real_escape_string().

the insert() method appears to have a problem;
       public function insert($sql) {
               $this->result_id = mysql_query($sql);
               return $this->select_id;
       }
namely, its returning an instance variable that isnt set anywhere else.

i see no method named update() or delete() (or drop() [although im not sure
if
you really need that]).  but im guessing you are probly using insert() for
these
sorts of queries.  you should either create these methods and have them use
a
common function w/ private access that does the query and stores
mysql_affected_rows(), or at the very least rename insert() to something
more
appropriate.

im not sure why you would name a call to mysql_insert_id(), select_id(); it
seems
better to preserve the original name.

you might also want methods that allow iteration over the result set, rather
than
just a single method which buffers the entire result set into an array and
returns it.

-nathan

[Index of Archives]     [PHP Home]     [Apache Users]     [PHP on Windows]     [Kernel Newbies]     [PHP Install]     [PHP Classes]     [Pear]     [Postgresql]     [Postgresql PHP]     [PHP on Windows]     [PHP Database Programming]     [PHP SOAP]

  Powered by Linux