|
Posted by Rik on 05/26/06 16:44
Bob Bedford wrote:
> hello
>
> I'm looking for some functions or objects allowing to
> select-insert-update-delete from any table in a mysql database
> without the
> need to create a new query every time. Example:
>
>
selectdatas(array('field1','field2','fieldn'),array('table1','tablen'),array
('left
> join,idy','inner join, idx'))
>
> then the function build the query, execute it and then return an
> object with
> the query result.
>
> I must build a database driven site that is 90% of the time spent on
> building queries. If I may avoid build them manually it will help me
> a lot
> and let me gain some days of programming.
I've tried that in the past. My conclusion was that in most cases, if you
want your queries to be flexible, use joins, where-clauses, etc, you end up
with exactly the same amount or work in writing the queries. Think about it:
if queries could be shorter, the SQL would be shorter. The advantage you do
get is an extra check wether a certain query is allowed to the specific
user, and you can control some of the output.
For a certain project specifically you could always try to figure out which
queries are used several times, and make a template for them. It won't save
you much coding time in my opinion though, but it will make your code more
readable.
Now I have a database object, that:
- takes car of connecting.
- saves querystrings and errors for debugging purposes.
- on selects returns a complete associative array, with (if existing) the
primary key as main key, 0 if no rows match, false if there's an error in
the query.
- on insert returns mysql_insert_id() (or array of insert_id()'s or false on
error.
- on updates and deletes returns the number of rows affected, or false on
error.
One thing that's usefull here that the object calls a certain
database-connection specifically, so it's easier when working with more than
one database in a script.
That's about as much as I can gain from it without inventing my own database
syntax. I'm no genius, and don't think I personally can replace SQL with a
better alternative :-).
Grtz,
--
Rik Wasmus
[Back to original message]
|