Add transparent support for PDO into installer; further integration of PDO
authorDan Fuhry <dan@enanocms.org>
Wed, 21 Aug 2013 22:50:34 -0400
changeset 1378 e58294b867c1
parent 1377 fa2b0825bbc5
child 1379 5cbd678df965
Add transparent support for PDO into installer; further integration of PDO
includes/common.php
includes/common_cli.php
includes/dbal.php
install/includes/stages/database.php
install/includes/stages/install.php
language/english/core.json
plugins/SpecialPageFuncs.php
--- a/includes/common.php	Wed Aug 21 22:34:54 2013 -0400
+++ b/includes/common.php	Wed Aug 21 22:50:34 2013 -0400
@@ -217,7 +217,9 @@
 if ( !isset($dbdriver) )
 	$dbdriver = 'mysql';
 
-$db = new $dbdriver();
+$dbdriver_cls = have_pdo($dbdriver) ? "{$dbdriver}_pdo" : $dbdriver;
+
+$db = new $dbdriver_cls();
 $db->connect();
 
 profiler_log('Database connected');
--- a/includes/common_cli.php	Wed Aug 21 22:34:54 2013 -0400
+++ b/includes/common_cli.php	Wed Aug 21 22:50:34 2013 -0400
@@ -36,7 +36,9 @@
 if ( !isset($dbdriver) )
 	$dbdriver = 'mysql';
 
-$db = new $dbdriver();
+$dbdriver_cls = have_pdo($dbdriver) ? "{$dbdriver}_pdo" : $dbdriver;
+
+$db = new $dbdriver_cls();
 $db->connect();
 
 profiler_log('Database connected');
--- a/includes/dbal.php	Wed Aug 21 22:34:54 2013 -0400
+++ b/includes/dbal.php	Wed Aug 21 22:50:34 2013 -0400
@@ -32,6 +32,17 @@
 	echo "<b>$errtype:</b> $errstr<br />Error source:<pre>$debug</pre>";
 }
 
+/**
+ * Checks to see if a given pdo driver is available.
+ * @param string driver name
+ * @return bool
+ */
+
+function have_pdo($driver)
+{
+	return class_exists('PDO') && extension_loaded("pdo_$driver") && class_exists("{$driver}_pdo");
+}
+
 global $db_sql_parse_time;
 $db_sql_parse_time = 0;
 
@@ -40,7 +51,7 @@
 	var $row = array();
 	var $rowset = array();
 	var $errhandler;
-	var $dbms_name = 'MySQL';
+	var $dbms_name = 'MySQL (legacy)';
 	
 	/**
  	* Get a flat textual list of queries that have been made.
@@ -706,7 +717,7 @@
 	var $row = array();
 	var $rowset = array();
 	var $errhandler;
-	var $dbms_name = 'MySQL';
+	var $dbms_name = 'MySQL/PDO';
 	
 	/**
  	* Get a flat textual list of queries that have been made.
--- a/install/includes/stages/database.php	Wed Aug 21 22:34:54 2013 -0400
+++ b/install/includes/stages/database.php	Wed Aug 21 22:50:34 2013 -0400
@@ -27,7 +27,7 @@
 $pgsql_disable_reason = '';
 $mysql_disable = '';
 $pgsql_disable = '';
-if ( !function_exists('mysql_connect') )
+if ( !function_exists('mysql_connect') && !have_pdo("mysql") )
 {
 	$mysql_disable = ' disabled="disabled"';
 	$mysql_disable_reason = $lang->get('database_driver_err_no_mysql');
--- a/install/includes/stages/install.php	Wed Aug 21 22:34:54 2013 -0400
+++ b/install/includes/stages/install.php	Wed Aug 21 22:50:34 2013 -0400
@@ -29,7 +29,9 @@
 	return true;
 }
 
-$db = new $dbdriver();
+$dbdriver_cls = have_pdo($dbdriver) ? "{$dbdriver}_pdo" : $dbdriver;
+
+$db = new $dbdriver_cls();
 $result = $db->connect();
 if ( !$result )
 {
--- a/language/english/core.json	Wed Aug 21 22:34:54 2013 -0400
+++ b/language/english/core.json	Wed Aug 21 22:50:34 2013 -0400
@@ -46,6 +46,7 @@
 			enano_about_lbl_webserver: 'Web server:',
 			enano_about_lbl_serverplatform: 'Server platform:',
 			enano_about_lbl_phpversion: '<a href="http://www.php.net/">PHP</a> version:',
+			enano_about_lbl_dbdriver: 'Database driver:',
 			enano_about_lbl_mysqlversion: '<a href="http://www.mysql.com/">MySQL</a> version:',
 			enano_about_lbl_pgsqlversion: '<a href="http://www.postgresql.org/">PostgreSQL</a> version:',
 			direction: 'ltr'
--- a/plugins/SpecialPageFuncs.php	Wed Aug 21 22:34:54 2013 -0400
+++ b/plugins/SpecialPageFuncs.php	Wed Aug 21 22:50:34 2013 -0400
@@ -486,20 +486,21 @@
 			<tr><td style="width: 100px;" class="row1"><?php echo $lang->get('meta_enano_about_lbl_enanoversion'); ?></td><td class="row1"><?php echo enano_version(true) . ' (' . enano_codename() . ')'; ?></td></tr>
 			<tr><td style="width: 100px;" class="row2"><?php echo $lang->get('meta_enano_about_lbl_webserver'); ?></td><td class="row2"><?php if(isset($_SERVER['SERVER_SOFTWARE'])) echo $_SERVER['SERVER_SOFTWARE']; else echo 'Unable to determine web server software.'; ?></td></tr>
 			<tr><td style="width: 100px;" class="row1"><?php echo $lang->get('meta_enano_about_lbl_serverplatform'); ?></td><td class="row1"><?php echo $platform; ?></td></tr>
-			<tr><td style="width: 100px;" class="row2"><?php echo $lang->get('meta_enano_about_lbl_phpversion'); ?></td><td class="row2"><?php echo PHP_VERSION; ?></td></tr>
+			<tr><td style="width: 100px;" class="row2"><?php echo $lang->get('meta_enano_about_lbl_dbdriver'); ?></td><td class="row2"><?php echo $db->dbms_name; ?></td></tr>
+			<tr><td style="width: 100px;" class="row1"><?php echo $lang->get('meta_enano_about_lbl_phpversion'); ?></td><td class="row1"><?php echo PHP_VERSION; ?></td></tr>
 			<?php
 			switch(ENANO_DBLAYER)
 			{
 				case 'MYSQL':
 					?>
-					<tr><td style="width: 100px;" class="row1"><?php echo $lang->get('meta_enano_about_lbl_mysqlversion'); ?></td><td class="row1"><?php echo $db->get_server_version(); ?></td></tr>
+					<tr><td style="width: 100px;" class="row2"><?php echo $lang->get('meta_enano_about_lbl_mysqlversion'); ?></td><td class="row2"><?php echo $db->get_server_version(); ?></td></tr>
 					<?php
 					break;
 				case 'PGSQL':
 					$pg_serverdata = pg_version($db->_conn);
 					$pg_version = $pg_serverdata['server'];
 					?>
-					<tr><td style="width: 100px;" class="row1"><?php echo $lang->get('meta_enano_about_lbl_pgsqlversion'); ?></td><td class="row1"><?php echo $pg_version; ?></td></tr>
+					<tr><td style="width: 100px;" class="row2"><?php echo $lang->get('meta_enano_about_lbl_pgsqlversion'); ?></td><td class="row2"><?php echo $pg_version; ?></td></tr>
 					<?php
 					break;
 			}