Jump to content

Detecting possible database engines compatible with php installed on the compute


Recommended Posts

Alright I'm designing a database library so that when the user installs my application to their server it will allow you to select the database type out of a list of available database engines. Also allowing you to chose which server/database engine/database/table/format for every piece of data taken from the database, making it extremely easy to install it on a system which uses a series of database engines/databases for data carried across multiple types of applications without needing to modify files.

 

 

My current issue is generating a list of possible database engines and checking to see which ones are installed on the system and enabled through php. Any help would be much appreciated, thank-you in advance.

Just about only general thing you can check is what PHP extensions are installed. Other than that you don't really have means of checking what is available (other than trying to connect using default settings). Perhaps you cold also grab a process list from system and see what's there.

You can try this:

 

define('MYSQL_ENABLED', function_exists('mysql_connect') ? true : false);
define('SQLITE_ENABLED', function_exists('sqlite_open') ? true : false);
//..

 

Then when the user selects a database you can verify that it is available.

Now i feel pretty stupid.

 

That is generally called the learning process :) If you knew all you probably wouldn't be here instead making billion dollar applications ultra-optimized to execute in pico-seconds :D Hell you would probably take a vacation on Pluto or some other Galaxy far, far away :P

Well I figured that if the user selected for example mysql then a logical step would be to try to connect using his provided input. However if the extension isn't loaded/installed then those functions aren't available unless I'm wrong at this and they are even if the extension is loaded or not but then what is their default implementation?

 

I don't fully understand what you mean by: "no reliable way of checking if/what database system is available"

From original post

My current issue is generating a list of possible database engines and checking to see which ones are installed on the system and enabled through php.

 

On another note: Even if say ext/mysql is not available, there still may be ext/mysqli or PDO_mysql.

On another note: Even if say ext/mysql is not available, there still may be ext/mysqli or PDO_mysql.

 

Ok yeah but you can solve that as:

 

define('MYSQL_ENABLED', function_exists('mysql_connect'));
define('MYSQLi_ENABLED', function_exists('mysqli_connect'));

 

Doesn't PDO use the mysql or mysqli extension?

Doesn't PDO use the mysql or mysqli extension?

No. It uses its own function library.

 

Well this is all new to me till now I never have had this problem. I do find it interesting as this means that I would be able to leave the mysql and mysqli extension disabled and just include the pdo extension and still be able to connect to any (supported) database. I now understand what Mchl meant as I can check for mysql or mysqli but the problem rises when it comes to PDO as it may be enabled but provides no means to verify a mysql server is present besides instantiating PDO with the MySQL driver and check for an error but then again is it because the user mistyped the password or the lack of the mysql presence.

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.