0

I'm developing an application in PHP 5.3, they want switch between MySQL and PostgreSQL and oracle easily, they want edit just "host" and "Dbname" and "password" and choose the target database then my script must work. now I'm using the switch operator to select between DBMS's and I use PDO, but even with PDO there is difference in code (connect, select , insert into, update ...) between Oracle and MySQL and PostgreSQL. I'm looking for a solution, maybe a design pattern or something to help me reduce code, I don't like a lot of 'switch' and 'if else' in my code.

user2601513
  • 51
  • 2
  • 4

1 Answers1

0

What you are looking for is called an ORM (Object Relational Mapping) and there is a good post here: Good PHP ORM Library? about good options in PHP.

Community
  • 1
  • 1
seanmk
  • 1,934
  • 15
  • 28
  • yes but ORM cause loss of performance, and my script is an ETL – user2601513 Jul 20 '13 at 04:26
  • If you can keep your SQL to a very, very small subset of the ANSI standard then you might be able to at least use the same SQL and abstract your connection code out into another class. However, the amount you can do with code that is really portable is dismal. Here's another thread that might help: http://stackoverflow.com/questions/784900/why-does-no-database-fully-support-ansi-or-iso-sql-standards – seanmk Jul 20 '13 at 04:34
  • Also, it is probably worth mentioning that the idea that ORM inherently causes a loss of performance is false. ORM's are not usually as good as a DBA at optimizing their queries, but people often blame the ORM when their real problem is that they haven't added the right indexes to their tables. Using an ORM doesn't exempt you from creating a sensible schema. If you are really worried about performance I would suggest using a language runtime with a good JIT compiler like the Oracle JRE or MS .Net and a database designed for data warehousing. – seanmk Jul 20 '13 at 04:41