Re: Better DB Class MySQL
| From: | Nathan Nobbe | Date: | Sun, 10 Feb 2008 00:40:40 +0000 |
| Subject: | Re: Better DB Class MySQL | ||
| References: | 1 | Groups: | php.general |
| Request: | Send a blank email to php-general+get-269016@lists.php.net to get a copy of this message | ||
On Feb 9, 2008 7:03 PM, nihilism machine <nihilismmachine@gmail.com> 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