Skip to content
This repository
Browse code

BUGFIX Updating MySQLDatabaseConfigurationHelper to check for MySQLi

instead of mysql_connect and other old function usage, as we've moved to
MySQLi in MySQLDatabase.php now
  • Loading branch information...
commit b03cf04dbd60219dc4f758030f3492bb0539a70f 1 parent c7ca63e
Sean Harvey authored April 28, 2012
2  _register_database.php
@@ -8,7 +8,7 @@
8 8
 		'class' => 'MySQLDatabase',
9 9
 		'title' => 'MySQL 5.0+',
10 10
 		'helperPath' => $frameworkPath . '/dev/install/MySQLDatabaseConfigurationHelper.php',
11  
-		'supported' => function_exists('mysql_connect'),
  11
+		'supported' => class_exists('MySQLi'),
12 12
 	)
13 13
 );
14 14
 
28  dev/install/MySQLDatabaseConfigurationHelper.php
@@ -18,7 +18,7 @@ class MySQLDatabaseConfigurationHelper implements DatabaseConfigurationHelper {
18 18
 	 * @return boolean
19 19
 	 */
20 20
 	public function requireDatabaseFunctions($databaseConfig) {
21  
-		return (function_exists('mysql_connect')) ? true : false;
  21
+		return class_exists('MySQLi');
22 22
 	}
23 23
 
24 24
 	/**
@@ -29,12 +29,12 @@ public function requireDatabaseFunctions($databaseConfig) {
29 29
 	public function requireDatabaseServer($databaseConfig) {
30 30
 		$success = false;
31 31
 		$error = '';
32  
-		$conn = @mysql_connect($databaseConfig['server'], $databaseConfig['username'], $databaseConfig['password']);
33  
-		if($conn || mysql_errno() < 2000) {
  32
+		$conn = new MySQLi($databaseConfig['server'], $databaseConfig['username'], $databaseConfig['password']);
  33
+		if($conn && $conn->connect_errno < 2000) {
34 34
 			$success = true;
35 35
 		} else {
36 36
 			$success = false;
37  
-			$error = mysql_error();
  37
+			$error = ($conn) ? $conn->connect_error : '';
38 38
 		}
39 39
 		return array(
40 40
 			'success' => $success,
@@ -48,13 +48,13 @@ public function requireDatabaseServer($databaseConfig) {
48 48
 	 * @return mixed string Version number as string | boolean FALSE on failure
49 49
 	 */
50 50
 	public function getDatabaseVersion($databaseConfig) {
51  
-		$conn = @mysql_connect($databaseConfig['server'], $databaseConfig['username'], $databaseConfig['password']);
  51
+		$conn = new MySQLi($databaseConfig['server'], $databaseConfig['username'], $databaseConfig['password']);
52 52
 		if(!$conn) return false;
53  
-		$version = @mysql_get_server_info($conn);
  53
+		$version = $conn->server_info;
54 54
 		if(!$version) {
55 55
 			// fallback to trying a query
56  
-			$result = @mysql_query("SELECT VERSION()");
57  
-			$row = @mysql_fetch_array($result);
  56
+			$result = $conn->query('SELECT VERSION()');
  57
+			$row = $result->fetch_array();
58 58
 			if($row && isset($row[0])) {
59 59
 				$version = trim($row[0]);
60 60
 			}
@@ -93,12 +93,12 @@ public function requireDatabaseVersion($databaseConfig) {
93 93
 	public function requireDatabaseConnection($databaseConfig) {
94 94
 		$success = false;
95 95
 		$error = '';
96  
-		$conn = @mysql_connect($databaseConfig['server'], $databaseConfig['username'], $databaseConfig['password']);
  96
+		$conn = new MySQLi($databaseConfig['server'], $databaseConfig['username'], $databaseConfig['password']);
97 97
 		if($conn) {
98 98
 			$success = true;
99 99
 		} else {
100 100
 			$success = false;
101  
-			$error = mysql_error();
  101
+			$error = ($conn) ? $conn->connect_error : '';
102 102
 		}
103 103
 		return array(
104 104
 			'success' => $success,
@@ -116,13 +116,13 @@ public function requireDatabaseConnection($databaseConfig) {
116 116
 	public function requireDatabaseOrCreatePermissions($databaseConfig) {
117 117
 		$success = false;
118 118
 		$alreadyExists = false;
119  
-		$conn = @mysql_connect($databaseConfig['server'], $databaseConfig['username'], $databaseConfig['password']);
120  
-		if(@mysql_select_db($databaseConfig['database'], $conn)) {
  119
+		$conn = new MySQLi($databaseConfig['server'], $databaseConfig['username'], $databaseConfig['password']);
  120
+		if($conn && $conn->select_db($databaseConfig['database'])) {
121 121
 			$success = true;
122 122
 			$alreadyExists = true;
123 123
 		} else {
124  
-			if(@mysql_query("CREATE DATABASE testing123", $conn)) {
125  
-				mysql_query("DROP DATABASE testing123", $conn);
  124
+			if($conn && $conn->query('CREATE DATABASE testing123')) {
  125
+				mysql_query('DROP DATABASE testing123', $conn);
126 126
 				$success = true;
127 127
 				$alreadyExists = false;
128 128
 			}

0 notes on commit b03cf04

Please sign in to comment.
Something went wrong with that request. Please try again.