1

If I have $dbConn (a database connection) and I don't know if it's MySQL, MSSQL or PostgreSQL can I tell what type of connection it is?

Just wanted to know if there is a method to return the connection type of a resource id?

EDIT: Sorry, yes PHP added the tag

Phill Pafford
  • 83,471
  • 91
  • 263
  • 383
  • I can assume `PHP` I think, but which database layer are you talking about? – Quassnoi Apr 28 '11 at 17:25
  • Yes PHP (sry), Just wanted to see if there was a way (other than knowing) to test if a connection is to a MySQL, MSSQL or PostgreSQL database. It's just a thought I had and wanted to get some feedback – Phill Pafford Apr 28 '11 at 17:29
  • `var_dump` on the handle may identify its type, especially if the handle's an object and not just a simple int pointer into an internal table somewhere. – Marc B Apr 28 '11 at 17:32
  • what do you mean by, say, a "connection to MySQL"? A result of `mysql_connect`, a result of `odbc_connect('mysql')`, an instance of `PDO('mysql')` or what? – Quassnoi Apr 28 '11 at 17:33

1 Answers1

1
$connection = mysql_connect(...); 

$is_mysql = (get_resource_type($connection) == 'mysql link');
$is_ibase = (get_resource_type($connection) == 'Firebird/InterBase link'); // *

var_dump($is_mysql); // -> true

// * supposed to be "interbase link" but isn't any longer
AndreKR
  • 32,613
  • 18
  • 106
  • 168