user2203484
user2203484

Reputation: 77

Universal database connection

I'm building session handling mechanism in which I use a couple of sql queries. These queries are hard-coded, and no later user is supposed to change anything in there.

What type of sql connection should I use?

Usual mysql connection won't work if user will have another database installed etc.

User defines his type of the database in config files, but well, I guess I don't make queries for all types of them.

How can I handle this?

Upvotes: 0

Views: 317

Answers (1)

Ivan Yonkov
Ivan Yonkov

Reputation: 7034

Use PDO -> http://www.php.net/manual/en/pdo.connections.php

In this exmaple:

 $dbh = new PDO('mysql:host=localhost;dbname=test', $user, $pass);

change mysql with a variable $database_dirver, so the user will fill it up.

 $dbh = new PDO(''. $database_driver .':host=localhost;dbname=test', $user, $pass);

Upvotes: 1

Related Questions