Page 1 of 1

Help with extension_loaded() please

Posted: Sat Sep 23, 2006 10:08 am
by georgeoc
Hi all,

I want to use extension_loaded() to check my users' choice of DB server before I try and initiate a connection with ADODB. I am providing the following options for DB server:

mssql
mysql
oracle 8/9
postgres

I'd like to know the string for each of these to pass to the function (I'm guessing 'mysql' is correct, but for the others? I'm a bit concerned about the case-sensitivity of the function too), and also if this is a 100% solid check that the extension is loaded and supported by the PHP installation.

Thanks

Posted: Sat Sep 23, 2006 10:19 am
by feyd
  1. Load the extensions
  2. use get_loaded_extensions() to get an array of the extensions you have loaded and find them in it.
  3. strtolower() or strtoupper() may be of interest, as may strcasecmp().

Posted: Sat Sep 23, 2006 10:47 am
by georgeoc
Thanks feyd.

Is this good enough do you think?

Code: Select all

switch($conf['db_type'])
{
	case 'mssql':
		if (!extension_loaded('mssql')) return 'This installation of PHP has not loaded the MS SQL Server extension.';
		break;
	case 'mysql':
		if (!extension_loaded('mysql')) return 'This installation of PHP has not loaded the MySQL extension.';
		break;
	case 'oci8':
		if (!extension_loaded('oci8')) return 'This installation of PHP has not loaded the Oracle extension.';
		break;
	case 'postgres7':
		if (!extension_loaded('pgsql')) return 'This installation of PHP has not loaded the PostgreSQL extension.';
		break;
	default:
		return sprintf('[%s] is not a supported database type.', $conf['db_type']);
		break;
}
All I really need to know is the strings to pass to the function - are the 4 I have chosen all that will ever be used, or are the extensions referred to by other names?

Posted: Sat Sep 23, 2006 10:53 am
by feyd
I'm not going to dig up the names for you, sorry.

Posted: Sat Sep 23, 2006 10:56 am
by georgeoc
Hmm. OK.

I'm don't expect you to do the legwork - I'd just appreciate your expert opinion, and possibly an idea of where to look for an answer!