Help with extension_loaded() please

PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!

Moderator: General Moderators

Post Reply
georgeoc
Forum Contributor
Posts: 166
Joined: Wed Aug 09, 2006 4:21 pm
Location: London, UK

Help with extension_loaded() please

Post 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
User avatar
feyd
Neighborhood Spidermoddy
Posts: 31559
Joined: Mon Mar 29, 2004 3:24 pm
Location: Bothell, Washington, USA

Post 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().
georgeoc
Forum Contributor
Posts: 166
Joined: Wed Aug 09, 2006 4:21 pm
Location: London, UK

Post 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?
User avatar
feyd
Neighborhood Spidermoddy
Posts: 31559
Joined: Mon Mar 29, 2004 3:24 pm
Location: Bothell, Washington, USA

Post by feyd »

I'm not going to dig up the names for you, sorry.
georgeoc
Forum Contributor
Posts: 166
Joined: Wed Aug 09, 2006 4:21 pm
Location: London, UK

Post 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!
Post Reply