diff --git a/cake/libs/model/datasources/datasource.php b/cake/libs/model/datasources/datasource.php index c92f8aff6..fa7b6632d 100644 --- a/cake/libs/model/datasources/datasource.php +++ b/cake/libs/model/datasources/datasource.php @@ -364,6 +364,16 @@ class DataSource extends Object { function lastAffected($source = null) { return false; } +/** + * Check whether the conditions for the Datasource being available + * are satisfied. Often used from connect() to check for support + * before establishing a connection. + * + * @return boolean Whether or not the Datasources conditions for use are met. + **/ + function enabled() { + return true; + } /** * Returns true if the DataSource supports the given interface (method) * diff --git a/cake/libs/model/datasources/dbo/dbo_adodb.php b/cake/libs/model/datasources/dbo/dbo_adodb.php index 53d6f9601..45fa4048e 100644 --- a/cake/libs/model/datasources/dbo/dbo_adodb.php +++ b/cake/libs/model/datasources/dbo/dbo_adodb.php @@ -102,7 +102,9 @@ class DboAdodb extends DboSource { $adodb_driver = substr($config['connect'], 0, $persistent); $connect = 'PConnect'; } - + if (!$this->enabled()) { + return false; + } $this->_adodb = NewADOConnection($adodb_driver); $this->_adodbDataDict = NewDataDictionary($this->_adodb, $adodb_driver); @@ -114,6 +116,14 @@ class DboAdodb extends DboSource { $this->_adodbMetatyper = &$this->_adodb->execute('Select 1'); return $this->connected; } +/** + * Check that AdoDB is available. + * + * @return boolean + **/ + function enabled() { + return function_exists('NewADOConnection'); + } /** * Disconnects from database. * diff --git a/cake/libs/model/datasources/dbo/dbo_db2.php b/cake/libs/model/datasources/dbo/dbo_db2.php index 4e65d3b43..0942dee85 100644 --- a/cake/libs/model/datasources/dbo/dbo_db2.php +++ b/cake/libs/model/datasources/dbo/dbo_db2.php @@ -136,6 +136,14 @@ class DboDb2 extends DboSource { } return $this->connected; } +/** + * Check that the DB2 extension is installed/loaded + * + * @return boolean + **/ + function enabled() { + return extension_loaded('ibm_db2'); + } /** * Disconnects from database. * diff --git a/cake/libs/model/datasources/dbo/dbo_firebird.php b/cake/libs/model/datasources/dbo/dbo_firebird.php index d02c45b76..dc9cec15f 100644 --- a/cake/libs/model/datasources/dbo/dbo_firebird.php +++ b/cake/libs/model/datasources/dbo/dbo_firebird.php @@ -127,9 +127,18 @@ class DboFirebird extends DboSource { $connect = $config['connect']; $this->connected = false; + $this->connection = $connect($config['host'] . ':' . $config['database'], $config['login'], $config['password']); $this->connected = true; } +/** + * Check that the interbase extension is loaded + * + * @return boolean + **/ + function enabled() { + return extension_loaded('interbase'); + } /** * Disconnects from database. * diff --git a/cake/libs/model/datasources/dbo/dbo_mssql.php b/cake/libs/model/datasources/dbo/dbo_mssql.php index 1b1219d59..b93192f95 100644 --- a/cake/libs/model/datasources/dbo/dbo_mssql.php +++ b/cake/libs/model/datasources/dbo/dbo_mssql.php @@ -152,6 +152,14 @@ class DboMssql extends DboSource { } return $this->connected; } +/** + * Check that MsSQL is installed/loaded + * + * @return boolean + **/ + function enabled() { + return extension_loaded('mssql'); + } /** * Disconnects from database. * diff --git a/cake/libs/model/datasources/dbo/dbo_mysql.php b/cake/libs/model/datasources/dbo/dbo_mysql.php index 2d97e141c..58433beca 100644 --- a/cake/libs/model/datasources/dbo/dbo_mysql.php +++ b/cake/libs/model/datasources/dbo/dbo_mysql.php @@ -388,6 +388,14 @@ class DboMysql extends DboMysqlBase { return $this->connected; } +/** + * Check whether the MySQL extension is installed/loaded + * + * @return boolean + **/ + function enabled() { + return extension_loaded('mysql'); + } /** * Disconnects from database. * diff --git a/cake/libs/model/datasources/dbo/dbo_mysqli.php b/cake/libs/model/datasources/dbo/dbo_mysqli.php index b0adf8d2e..bf9797d43 100644 --- a/cake/libs/model/datasources/dbo/dbo_mysqli.php +++ b/cake/libs/model/datasources/dbo/dbo_mysqli.php @@ -83,6 +83,14 @@ class DboMysqli extends DboMysqlBase { } return $this->connected; } +/** + * Check that MySQLi is installed/enabled + * + * @return boolean + **/ + function enabled() { + return extension_loaded('mysqli'); + } /** * Disconnects from database. * diff --git a/cake/libs/model/datasources/dbo/dbo_odbc.php b/cake/libs/model/datasources/dbo/dbo_odbc.php index a8572a713..e68948668 100644 --- a/cake/libs/model/datasources/dbo/dbo_odbc.php +++ b/cake/libs/model/datasources/dbo/dbo_odbc.php @@ -105,6 +105,14 @@ class DboOdbc extends DboSource { return $this->connected; } +/** + * Check if the ODBC extension is installed/loaded + * + * @return boolean + **/ + function enabled() { + return extension_loaded('odbc'); + } /** * Disconnects from database. * diff --git a/cake/libs/model/datasources/dbo/dbo_postgres.php b/cake/libs/model/datasources/dbo/dbo_postgres.php index 2298fc019..192355fd6 100644 --- a/cake/libs/model/datasources/dbo/dbo_postgres.php +++ b/cake/libs/model/datasources/dbo/dbo_postgres.php @@ -122,6 +122,14 @@ class DboPostgres extends DboSource { } return $this->connected; } +/** + * Check if PostgreSQL is enabled/loaded + * + * @return boolean + **/ + function enabled() { + return extension_loaded('pgsql'); + } /** * Disconnects from database. * diff --git a/cake/libs/model/datasources/dbo/dbo_sqlite.php b/cake/libs/model/datasources/dbo/dbo_sqlite.php index c365b6fe0..005ffc6fe 100644 --- a/cake/libs/model/datasources/dbo/dbo_sqlite.php +++ b/cake/libs/model/datasources/dbo/dbo_sqlite.php @@ -113,6 +113,14 @@ class DboSqlite extends DboSource { } return $this->connected; } +/** + * Check that SQLite is enabled/installed + * + * @return boolean + **/ + function enabled() { + return extension_loaded('sqlite'); + } /** * Disconnects from database. * diff --git a/cake/libs/model/datasources/dbo/dbo_sybase.php b/cake/libs/model/datasources/dbo/dbo_sybase.php index 4bed00e43..45e8fd057 100644 --- a/cake/libs/model/datasources/dbo/dbo_sybase.php +++ b/cake/libs/model/datasources/dbo/dbo_sybase.php @@ -102,6 +102,14 @@ class DboSybase extends DboSource { $this->connected = sybase_select_db($config['database'], $this->connection); return $this->connected; } +/** + * Check that one of the sybase extensions is installed + * + * @return boolean + **/ + function enabled() { + return extension_loaded('sybase') || extension_loaded('sybase_ct'); + } /** * Disconnects from database. * diff --git a/cake/libs/model/datasources/dbo_source.php b/cake/libs/model/datasources/dbo_source.php index 1b10243d9..013a5baee 100644 --- a/cake/libs/model/datasources/dbo_source.php +++ b/cake/libs/model/datasources/dbo_source.php @@ -91,7 +91,9 @@ class DboSource extends DataSource { } parent::__construct($config); $this->fullDebug = Configure::read() > 1; - + if (!$this->enabled()) { + return false; + } if ($autoConnect) { return $this->connect(); } else {