MySQL or SQL Server
Posted
by user203708
on Stack Overflow
See other posts from Stack Overflow
or by user203708
Published on 2010-06-13T18:29:33Z
Indexed on
2010/06/13
18:42 UTC
Read the original article
Hit count: 279
I'm creating an application that I want to run on either MySQL or SQL Server (not both at the same time) I've created two PHP classes DatabaseMySQL and DatabaseSQLSVR and I'd like my application to know which database class to use based on a constant set up at install.
define(DB_TYPE, "mysql"); // or "sqlsrv"
I'm trying to think of the best way to handle this. My thought is to do an "if else" wherever I instantiate the database:
$db = (DB_TYPE == "mysql") ? new DatabaseMySQL : new DatabaseSQLSVR;
I know there has to be a better way of doing this though. Suppose I want to add a third database type later; I'll have to go and redo all my code. Yuk!! Any help would be much appreciated.
Thank
© Stack Overflow or respective owner