* forwarding to PHP general


"Kasper Skårhøj" <[EMAIL PROTECTED]> wrote... :

 
> There are millions of PHP-scripts using MySQL. Most 
> of them probably doesn't use an Database Abstraction Layer (DBAL) in
> order to support other databases. When the requirement is made some day
> that a script should support another DB than MySQL programmers are
> facing the challenge of literally rewrite most of their code to fit some
> DBAL, like ADOdb or whatever.

There are already tons of them written. The most famous ones are PEAR
and ADODB. No need reinventing the wheel, contributing, maybe.

> So my idea was to make a DBAL which basically offers a parallel set
> of functions to the current MySQL-functions (search/replace) but
> internally parses the queries and re-makes the query into something
> Oracle or MSSql or some third DB would understand. This would be totally
> transparent and give instant DBA to millions of PHP-scripts. A "MySQL
> emulator". For MySQL it wouldn't affect performance. For other DBs I
> would require a little parsing time of the query.

Parsing the query is
1) bad idea because I don't want anything to mess with my SQL code
2) does not substitute something and limits something else
3) when moving to another database you also change your database design,
this way the queries will have to be rewritten anyway


> I know this is not as simple as it sounds, but is it
> *totally impossible* since noone made it yet and if some of you think it
> is, please let me know why. I think the idea is obvious.

Pretty much impossible. Oh well, adding all the logic, you can reduce
the problems at most, but never to the perfection.

Consider this:

to select some data in mySQL you do "SELECT ..." while Oracle supports
stored procedures, where you will have to bind the variables with
OCIBindByName() function and a whole PL/SQL block as the query. How will
you accomplish that?

Also, databases differ bewteen themselves too much in the SQL itself,
which is never SQL92 compatible. Rewriting that will lead to many
unexpected results and, in most parts it is impossible. For instance, in
Oralce I can do:


SELECT
        *
FROM
        customers
WHERE
        customer_id = 
                SELECT
                        customer_id
                FROM
                        purchases
                WHERE
                        product_id = '$product' AND
                        rownum = 1
        )


How would you transform that from Oracle to mySQL? You'd need to whole
queries in mySQL for that thing...

The only solution is:

storing queries separately. Check out how I did that for ZoomStats:
www.sf.net/projects/zoomstats

I have also written about it at PHP Architect (www.phparch.com)



--
Maxim Maletsky
[EMAIL PROTECTED]



--
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php

Reply via email to