From: mark burdett Date: Wed, 25 May 2016 18:15:26 +0000 (+0200) Subject: CRM-17789 - replace mysql extension with mysqli X-Git-Url: https://vcs.fsf.org/?a=commitdiff_plain;h=fcf908c63fd0fc8afa791c09476cba067f156c08;p=civicrm-core.git CRM-17789 - replace mysql extension with mysqli --- diff --git a/CRM/Core/DAO.php b/CRM/Core/DAO.php index 4747adee2f..b80c09223b 100644 --- a/CRM/Core/DAO.php +++ b/CRM/Core/DAO.php @@ -1391,6 +1391,8 @@ FROM civicrm_domain foreach ($ids as $id) { if (isset($_DB_DATAOBJECT['RESULTS'][$id])) { if (is_resource($_DB_DATAOBJECT['RESULTS'][$id]->result)) { + // @fixme mysql_free_result() does not exist in PHP7. + // No fatal error, however, because mysqli result is not a resource. mysql_free_result($_DB_DATAOBJECT['RESULTS'][$id]->result); } unset($_DB_DATAOBJECT['RESULTS'][$id]); @@ -1636,17 +1638,13 @@ SELECT contact_id if (!$_dao) { // If this is an atypical case (e.g. preparing .sql files // before Civi has been installed), then we fallback to - // DB-less escaping helper (mysql_real_escape_string). + // DB-less escaping helper (addslashes). This is unsafe + // so should only be used on trusted strings. // Note: In typical usage, escapeString() will only // check one conditional ("if !$_dao") rather than // two conditionals ("if !defined(DSN)") if (!defined('CIVICRM_DSN')) { - if (function_exists('mysql_real_escape_string')) { - return mysql_real_escape_string($string); - } - else { - throw new CRM_Core_Exception("Cannot generate SQL. \"mysql_real_escape_string\" is missing. Have you installed PHP \"mysql\" extension?"); - } + return addslashes($string); } $_dao = new CRM_Core_DAO(); diff --git a/CRM/Report/Form/Mailing/Detail.php b/CRM/Report/Form/Mailing/Detail.php index b27ce99a85..19bcee840b 100644 --- a/CRM/Report/Form/Mailing/Detail.php +++ b/CRM/Report/Form/Mailing/Detail.php @@ -452,7 +452,7 @@ class CRM_Report_Form_Mailing_Detail extends CRM_Report_Form { $mailing->query($query); while ($mailing->fetch()) { - $data[mysql_real_escape_string($mailing->name)] = $mailing->name; + $data[$mailing->escape($mailing->name)] = $mailing->name; } return $data; diff --git a/CRM/Report/Form/Mailing/Summary.php b/CRM/Report/Form/Mailing/Summary.php index facc20790a..deecbd83ec 100644 --- a/CRM/Report/Form/Mailing/Summary.php +++ b/CRM/Report/Form/Mailing/Summary.php @@ -298,7 +298,7 @@ class CRM_Report_Form_Mailing_Summary extends CRM_Report_Form { $mailing->query($query); while ($mailing->fetch()) { - $data[mysql_real_escape_string($mailing->name)] = $mailing->name; + $data[$mailing->escape($mailing->name)] = $mailing->name; } return $data; diff --git a/Civi/Install/Requirements.php b/Civi/Install/Requirements.php index d7811458eb..16fe39bb6b 100644 --- a/Civi/Install/Requirements.php +++ b/Civi/Install/Requirements.php @@ -205,11 +205,11 @@ class Requirements { $results = array( 'title' => 'CiviCRM MySQL check', 'severity' => $this::REQUIREMENT_OK, - 'details' => 'Function mysql_connect() found', + 'details' => 'Function mysqli_connect() found', ); - if (!function_exists('mysql_connect')) { + if (!function_exists('mysqli_connect')) { $results['severity'] = $this::REQUIREMENT_ERROR; - $results['details'] = 'Function mysql_connect() does not exist'; + $results['details'] = 'Function mysqli_connect() does not exist'; } return $results; @@ -227,16 +227,16 @@ class Requirements { 'details' => "Connected", ); - $conn = @mysql_connect($db_config['host'], $db_config['username'], $db_config['password']); + $conn = @mysqli_connect($db_config['host'], $db_config['username'], $db_config['password']); if (!$conn) { - $results['details'] = mysql_error(); + $results['details'] = mysqli_connect_error(); $results['severity'] = $this::REQUIREMENT_ERROR; return $results; } - if (!@mysql_select_db($db_config['database'], $conn)) { - $results['details'] = mysql_error(); + if (!@mysqli_select_db($conn, $db_config['database'])) { + $results['details'] = mysqli_error($conn); $results['severity'] = $this::REQUIREMENT_ERROR; return $results; } @@ -256,8 +256,8 @@ class Requirements { 'severity' => $this::REQUIREMENT_OK, ); - $conn = @mysql_connect($db_config['host'], $db_config['username'], $db_config['password']); - if (!$conn || !($info = mysql_get_server_info($conn))) { + $conn = @mysqli_connect($db_config['host'], $db_config['username'], $db_config['password']); + if (!$conn || !($info = mysqli_get_server_info($conn))) { $results['severity'] = $this::REQUIREMENT_WARNING; $results['details'] = "Cannot determine the version of MySQL installed. Please ensure at least version {$min} is installed."; return $results; @@ -285,14 +285,14 @@ class Requirements { 'details' => 'Could not determine if MySQL has InnoDB support. Assuming none.', ); - $conn = @mysql_connect($db_config['host'], $db_config['username'], $db_config['password']); + $conn = @mysqli_connect($db_config['host'], $db_config['username'], $db_config['password']); if (!$conn) { return $results; } $innodb_support = FALSE; - $result = mysql_query("SHOW ENGINES", $conn); - while ($values = mysql_fetch_array($result)) { + $result = mysqli_query($conn, "SHOW ENGINES"); + while ($values = mysqli_fetch_array($result)) { if ($values['Engine'] == 'InnoDB') { if (strtolower($values['Support']) == 'yes' || strtolower($values['Support']) == 'default') { $innodb_support = TRUE; @@ -320,27 +320,27 @@ class Requirements { 'details' => 'MySQL server supports temporary tables', ); - $conn = @mysql_connect($db_config['host'], $db_config['username'], $db_config['password']); + $conn = @mysqli_connect($db_config['host'], $db_config['username'], $db_config['password']); if (!$conn) { $results['severity'] = $this::REQUIREMENT_ERROR; $results['details'] = "Could not connect to database"; return $results; } - if (!@mysql_select_db($db_config['database'], $conn)) { + if (!@mysqli_select_db($conn, $db_config['database'])) { $results['severity'] = $this::REQUIREMENT_ERROR; $results['details'] = "Could not select the database"; return $results; } - $r = mysql_query('CREATE TEMPORARY TABLE civicrm_install_temp_table_test (test text)', $conn); + $r = mysqli_query($conn, 'CREATE TEMPORARY TABLE civicrm_install_temp_table_test (test text)'); if (!$r) { $results['severity'] = $this::REQUIREMENT_ERROR; $results['details'] = "Database does not support creation of temporary tables"; return $results; } - mysql_query('DROP TEMPORARY TABLE civicrm_install_temp_table_test'); + mysqli_query($conn, 'DROP TEMPORARY TABLE civicrm_install_temp_table_test'); return $results; } @@ -356,36 +356,36 @@ class Requirements { 'details' => 'Database supports MySQL triggers', ); - $conn = @mysql_connect($db_config['host'], $db_config['username'], $db_config['password']); + $conn = @mysqli_connect($db_config['host'], $db_config['username'], $db_config['password']); if (!$conn) { $results['severity'] = $this::REQUIREMENT_ERROR; $results['details'] = 'Could not connect to database'; return $results; } - if (!@mysql_select_db($db_config['database'], $conn)) { + if (!@mysqli_select_db($conn, $db_config['database'])) { $results['severity'] = $this::REQUIREMENT_ERROR; $results['details'] = "Could not select the database"; return $results; } - $r = mysql_query('CREATE TABLE civicrm_install_temp_table_test (test text)', $conn); + $r = mysqli_query($conn, 'CREATE TABLE civicrm_install_temp_table_test (test text)'); if (!$r) { $results['severity'] = $this::REQUIREMENT_ERROR; $results['details'] = 'Could not create a table to run test'; return $results; } - $r = mysql_query('CREATE TRIGGER civicrm_install_temp_table_test_trigger BEFORE INSERT ON civicrm_install_temp_table_test FOR EACH ROW BEGIN END'); + $r = mysqli_query($conn, 'CREATE TRIGGER civicrm_install_temp_table_test_trigger BEFORE INSERT ON civicrm_install_temp_table_test FOR EACH ROW BEGIN END'); if (!$r) { $results['severity'] = $this::REQUIREMENT_ERROR; $results['details'] = 'Database does not support creation of triggers'; } else { - mysql_query('DROP TRIGGER civicrm_install_temp_table_test_trigger'); + mysqli_query($conn, 'DROP TRIGGER civicrm_install_temp_table_test_trigger'); } - mysql_query('DROP TABLE civicrm_install_temp_table_test'); + mysqli_query($conn, 'DROP TABLE civicrm_install_temp_table_test'); return $results; } @@ -401,21 +401,21 @@ class Requirements { 'details' => 'MySQL server auto_increment_increment is 1', ); - $conn = @mysql_connect($db_config['host'], $db_config['username'], $db_config['password']); + $conn = @mysqli_connect($db_config['host'], $db_config['username'], $db_config['password']); if (!$conn) { $results['severity'] = $this::REQUIREMENT_ERROR; $results['details'] = 'Could not connect to database'; return $results; } - $r = mysql_query("SHOW variables like 'auto_increment_increment'", $conn); + $r = mysqli_query($conn, "SHOW variables like 'auto_increment_increment'"); if (!$r) { $results['severity'] = $this::REQUIREMENT_ERROR; $results['details'] = 'Could not query database server variables'; return $results; } - $values = mysql_fetch_row($r); + $values = mysqli_fetch_row($r); if ($values[1] != 1) { $results['severity'] = $this::REQUIREMENT_ERROR; $results['details'] = 'MySQL server auto_increment_increment is not 1'; @@ -437,26 +437,26 @@ class Requirements { 'details' => 'MySQL thread_stack is OK', ); - $conn = @mysql_connect($db_config['server'], $db_config['username'], $db_config['password']); + $conn = @mysqli_connect($db_config['server'], $db_config['username'], $db_config['password']); if (!$conn) { $results['severity'] = $this::REQUIREMENT_ERROR; $results['details'] = 'Could not connect to database'; return $results; } - if (!@mysql_select_db($db_config['database'], $conn)) { + if (!@mysqli_select_db($conn, $db_config['database'])) { $results['severity'] = $this::REQUIREMENT_ERROR; $results['details'] = 'Could not select the database'; return $results; } - $r = mysql_query("SHOW VARIABLES LIKE 'thread_stack'", $conn); // bytes => kb + $r = mysqli_query($conn, "SHOW VARIABLES LIKE 'thread_stack'"); // bytes => kb if (!$r) { $results['severity'] = $this::REQUIREMENT_ERROR; $results['details'] = 'Could not query thread_stack value'; } else { - $values = mysql_fetch_row($r); + $values = mysqli_fetch_row($r); if ($values[1] < (1024 * $min_thread_stack)) { $results['severity'] = $this::REQUIREMENT_ERROR; $results['details'] = 'MySQL thread_stack is ' . ($values[1] / 1024) . "kb (minimum required is {$min_thread_stack} kb"; @@ -478,43 +478,43 @@ class Requirements { 'details' => 'Can successfully lock and unlock tables', ); - $conn = @mysql_connect($db_config['server'], $db_config['username'], $db_config['password']); + $conn = @mysqli_connect($db_config['server'], $db_config['username'], $db_config['password']); if (!$conn) { $results['severity'] = $this::REQUIREMENT_ERROR; $results['details'] = 'Could not connect to database'; return $results; } - if (!@mysql_select_db($db_config['database'], $conn)) { + if (!@mysqli_select_db($conn, $db_config['database'])) { $results['severity'] = $this::REQUIREMENT_ERROR; $results['details'] = 'Could not select the database'; - mysql_close($conn); + mysqli_close($conn); return $results; } - $r = mysql_query('CREATE TEMPORARY TABLE civicrm_install_temp_table_test (test text)', $conn); + $r = mysqli_query($conn, 'CREATE TEMPORARY TABLE civicrm_install_temp_table_test (test text)'); if (!$r) { $results['severity'] = $this::REQUIREMENT_ERROR; $results['details'] = 'Could not create a table'; - mysql_close($conn); + mysqli_close($conn); return $results; } - $r = mysql_query('LOCK TABLES civicrm_install_temp_table_test WRITE', $conn); + $r = mysqli_query($conn, 'LOCK TABLES civicrm_install_temp_table_test WRITE'); if (!$r) { $results['severity'] = $this::REQUIREMENT_ERROR; $results['details'] = 'Could not obtain a write lock'; - mysql_close($conn); + mysqli_close($conn); return $results; } - $r = mysql_query('UNLOCK TABLES', $conn); + $r = mysqli_query($conn, 'UNLOCK TABLES'); if (!$r) { $results['severity'] = $this::REQUIREMENT_ERROR; $results['details'] = 'Could not release table lock'; } - mysql_close($conn); + mysqli_close($conn); return $results; } diff --git a/install/civicrm.php b/install/civicrm.php index c23bf6020b..1d707cadef 100644 --- a/install/civicrm.php +++ b/install/civicrm.php @@ -97,7 +97,7 @@ function civicrm_main(&$config) { civicrm_setup($files_dirname); } - $dsn = "mysql://{$config['mysql']['username']}:{$config['mysql']['password']}@{$config['mysql']['server']}/{$config['mysql']['database']}?new_link=true"; + $dsn = "mysqli://{$config['mysql']['username']}:{$config['mysql']['password']}@{$config['mysql']['server']}/{$config['mysql']['database']}?new_link=true"; civicrm_source($dsn, $sqlPath . DIRECTORY_SEPARATOR . 'civicrm.mysql'); diff --git a/install/index.php b/install/index.php index 276c1c4ca1..b21a204602 100644 --- a/install/index.php +++ b/install/index.php @@ -407,7 +407,7 @@ else { * $description[2] - The test error to show, if it goes wrong */ class InstallRequirements { - var $errors, $warnings, $tests; + var $errors, $warnings, $tests, $conn; // @see CRM_Upgrade_Form::MINIMUM_THREAD_STACK const MINIMUM_THREAD_STACK = 192; @@ -418,7 +418,7 @@ class InstallRequirements { * @param $dbName */ public function checkdatabase($databaseConfig, $dbName) { - if ($this->requireFunction('mysql_connect', + if ($this->requireFunction('mysqli_connect', array( ts("PHP Configuration"), ts("MySQL support"), @@ -448,8 +448,8 @@ class InstallRequirements { array( ts("MySQL %1 Configuration", array(1 => $dbName)), ts("MySQL version at least %1", array(1 => '5.1')), - ts("MySQL version %1 or higher is required, you are running MySQL %2.", array(1 => '5.1', 2 => mysql_get_server_info())), - ts("MySQL %1", array(1 => mysql_get_server_info())), + ts("MySQL version %1 or higher is required, you are running MySQL %2.", array(1 => '5.1', 2 => mysqli_get_server_info($this->conn))), + ts("MySQL %1", array(1 => mysqli_get_server_info($this->conn))), ) ); $this->requireMySQLAutoIncrementIncrementOne($databaseConfig['server'], @@ -666,7 +666,7 @@ class InstallRequirements { )); // Check for MySQL support - $this->requireFunction('mysql_connect', array( + $this->requireFunction('mysqli_connect', array( ts("PHP Configuration"), ts("MySQL support"), ts("MySQL support not included in PHP."), @@ -943,13 +943,13 @@ class InstallRequirements { */ public function requireMysqlConnection($server, $username, $password, $testDetails) { $this->testing($testDetails); - $conn = @mysql_connect($server, $username, $password); + $this->conn = @mysqli_connect($server, $username, $password); - if ($conn) { + if ($this->conn) { return TRUE; } else { - $testDetails[2] .= ": " . mysql_error(); + $testDetails[2] .= ": " . mysqli_connect_error(); $this->error($testDetails); } } @@ -960,13 +960,13 @@ class InstallRequirements { */ public function requireMySQLServer($server, $testDetails) { $this->testing($testDetails); - $conn = @mysql_connect($server, NULL, NULL); + $conn = @mysqli_connect($server, NULL, NULL); - if ($conn || mysql_errno() < 2000) { + if ($conn || mysqli_connect_errno() < 2000) { return TRUE; } else { - $testDetails[2] .= ": " . mysql_error(); + $testDetails[2] .= ": " . mysqli_connect_error(); $this->error($testDetails); } } @@ -978,13 +978,13 @@ class InstallRequirements { public function requireMySQLVersion($version, $testDetails) { $this->testing($testDetails); - if (!mysql_get_server_info()) { + if (!mysqli_get_server_info($this->conn)) { $testDetails[2] = ts('Cannot determine the version of MySQL installed. Please ensure at least version %1 is installed.', array(1 => $version)); $this->warning($testDetails); } else { list($majorRequested, $minorRequested) = explode('.', $version); - list($majorHas, $minorHas) = explode('.', mysql_get_server_info()); + list($majorHas, $minorHas) = explode('.', mysqli_get_server_info($this->conn)); if (($majorHas > $majorRequested) || ($majorHas == $majorRequested && $minorHas >= $minorRequested)) { return TRUE; @@ -1005,7 +1005,7 @@ class InstallRequirements { */ public function requireMySQLInnoDB($server, $username, $password, $database, $testDetails) { $this->testing($testDetails); - $conn = @mysql_connect($server, $username, $password); + $conn = @mysqli_connect($server, $username, $password); if (!$conn) { $testDetails[2] .= ' ' . ts("Could not determine if MySQL has InnoDB support. Assuming no."); $this->error($testDetails); @@ -1013,8 +1013,8 @@ class InstallRequirements { } $innodb_support = FALSE; - $result = mysql_query("SHOW ENGINES", $conn); - while ($values = mysql_fetch_array($result)) { + $result = mysqli_query($conn, "SHOW ENGINES"); + while ($values = mysqli_fetch_array($result)) { if ($values['Engine'] == 'InnoDB') { if (strtolower($values['Support']) == 'yes' || strtolower($values['Support']) == 'default' @@ -1040,25 +1040,25 @@ class InstallRequirements { */ public function requireMySQLTempTables($server, $username, $password, $database, $testDetails) { $this->testing($testDetails); - $conn = @mysql_connect($server, $username, $password); + $conn = @mysqli_connect($server, $username, $password); if (!$conn) { $testDetails[2] = ts('Could not login to the database.'); $this->error($testDetails); return; } - if (!@mysql_select_db($database, $conn)) { + if (!@mysqli_select_db($conn, $database)) { $testDetails[2] = ts('Could not select the database.'); $this->error($testDetails); return; } - $result = mysql_query('CREATE TEMPORARY TABLE civicrm_install_temp_table_test (test text)', $conn); + $result = mysqli_query($conn, 'CREATE TEMPORARY TABLE civicrm_install_temp_table_test (test text)'); if (!$result) { $testDetails[2] = ts('Could not create a temp table.'); $this->error($testDetails); } - $result = mysql_query('DROP TEMPORARY TABLE civicrm_install_temp_table_test'); + $result = mysqli_query($conn, 'DROP TEMPORARY TABLE civicrm_install_temp_table_test'); } /** @@ -1070,34 +1070,34 @@ class InstallRequirements { */ public function requireMySQLTrigger($server, $username, $password, $database, $testDetails) { $this->testing($testDetails); - $conn = @mysql_connect($server, $username, $password); + $conn = @mysqli_connect($server, $username, $password); if (!$conn) { $testDetails[2] = ts('Could not login to the database.'); $this->error($testDetails); return; } - if (!@mysql_select_db($database, $conn)) { + if (!@mysqli_select_db($conn, $database)) { $testDetails[2] = ts('Could not select the database.'); $this->error($testDetails); return; } - $result = mysql_query('CREATE TABLE civicrm_install_temp_table_test (test text)', $conn); + $result = mysqli_query($conn, 'CREATE TABLE civicrm_install_temp_table_test (test text)'); if (!$result) { $testDetails[2] = ts('Could not create a table in the database.'); $this->error($testDetails); } - $result = mysql_query('CREATE TRIGGER civicrm_install_temp_table_test_trigger BEFORE INSERT ON civicrm_install_temp_table_test FOR EACH ROW BEGIN END'); + $result = mysqli_query($conn, 'CREATE TRIGGER civicrm_install_temp_table_test_trigger BEFORE INSERT ON civicrm_install_temp_table_test FOR EACH ROW BEGIN END'); if (!$result) { - mysql_query('DROP TABLE civicrm_install_temp_table_test'); + mysqli_query($conn, 'DROP TABLE civicrm_install_temp_table_test'); $testDetails[2] = ts('Could not create a database trigger.'); $this->error($testDetails); } - mysql_query('DROP TRIGGER civicrm_install_temp_table_test_trigger'); - mysql_query('DROP TABLE civicrm_install_temp_table_test'); + mysqli_query($conn, 'DROP TRIGGER civicrm_install_temp_table_test_trigger'); + mysqli_query($conn, 'DROP TABLE civicrm_install_temp_table_test'); } @@ -1110,43 +1110,43 @@ class InstallRequirements { */ public function requireMySQLLockTables($server, $username, $password, $database, $testDetails) { $this->testing($testDetails); - $conn = @mysql_connect($server, $username, $password); + $conn = @mysqli_connect($server, $username, $password); if (!$conn) { $testDetails[2] = ts('Could not connect to the database server.'); $this->error($testDetails); return; } - if (!@mysql_select_db($database, $conn)) { + if (!@mysqli_select_db($conn, $database)) { $testDetails[2] = ts('Could not select the database.'); $this->error($testDetails); return; } - $result = mysql_query('CREATE TEMPORARY TABLE civicrm_install_temp_table_test (test text)', $conn); + $result = mysqli_query($conn, 'CREATE TEMPORARY TABLE civicrm_install_temp_table_test (test text)'); if (!$result) { $testDetails[2] = ts('Could not create a table in the database.'); $this->error($testDetails); return; } - $result = mysql_query('LOCK TABLES civicrm_install_temp_table_test WRITE', $conn); + $result = mysqli_query($conn, 'LOCK TABLES civicrm_install_temp_table_test WRITE'); if (!$result) { $testDetails[2] = ts('Could not obtain a write lock for the database table.'); $this->error($testDetails); - $result = mysql_query('DROP TEMPORARY TABLE civicrm_install_temp_table_test'); + $result = mysqli_query($conn, 'DROP TEMPORARY TABLE civicrm_install_temp_table_test'); return; } - $result = mysql_query('UNLOCK TABLES', $conn); + $result = mysqli_query($conn, 'UNLOCK TABLES'); if (!$result) { $testDetails[2] = ts('Could not release the lock for the database table.'); $this->error($testDetails); - $result = mysql_query('DROP TEMPORARY TABLE civicrm_install_temp_table_test'); + $result = mysqli_query($conn, 'DROP TEMPORARY TABLE civicrm_install_temp_table_test'); return; } - $result = mysql_query('DROP TEMPORARY TABLE civicrm_install_temp_table_test'); + $result = mysqli_query($conn, 'DROP TEMPORARY TABLE civicrm_install_temp_table_test'); } /** @@ -1157,21 +1157,21 @@ class InstallRequirements { */ public function requireMySQLAutoIncrementIncrementOne($server, $username, $password, $testDetails) { $this->testing($testDetails); - $conn = @mysql_connect($server, $username, $password); + $conn = @mysqli_connect($server, $username, $password); if (!$conn) { $testDetails[2] = ts('Could not connect to the database server.'); $this->error($testDetails); return; } - $result = mysql_query("SHOW variables like 'auto_increment_increment'", $conn); + $result = mysqli_query($conn, "SHOW variables like 'auto_increment_increment'"); if (!$result) { $testDetails[2] = ts('Could not query database server variables.'); $this->error($testDetails); return; } else { - $values = mysql_fetch_row($result); + $values = mysqli_fetch_row($result); if ($values[1] == 1) { $testDetails[3] = ts('MySQL server auto_increment_increment is 1'); } @@ -1191,26 +1191,26 @@ class InstallRequirements { */ public function requireMySQLThreadStack($server, $username, $password, $database, $minValueKB, $testDetails) { $this->testing($testDetails); - $conn = @mysql_connect($server, $username, $password); + $conn = @mysqli_connect($server, $username, $password); if (!$conn) { $testDetails[2] = ts('Could not connect to the database server.'); $this->error($testDetails); return; } - if (!@mysql_select_db($database, $conn)) { + if (!@mysqli_select_db($conn, $database)) { $testDetails[2] = ts('Could not select the database.'); $this->error($testDetails); return; } - $result = mysql_query("SHOW VARIABLES LIKE 'thread_stack'", $conn); // bytes => kb + $result = mysqli_query($conn, "SHOW VARIABLES LIKE 'thread_stack'"); // bytes => kb if (!$result) { $testDetails[2] = ts('Could not get information about the thread_stack of the database.'); $this->error($testDetails); } else { - $values = mysql_fetch_row($result); + $values = mysqli_fetch_row($result); if ($values[1] < (1024 * $minValueKB)) { $testDetails[2] = ts('MySQL "thread_stack" is %1 kb', array(1 => ($values[1] / 1024))); $this->error($testDetails); @@ -1235,10 +1235,10 @@ class InstallRequirements { $onlyRequire = FALSE ) { $this->testing($testDetails); - $conn = @mysql_connect($server, $username, $password); + $conn = @mysqli_connect($server, $username, $password); $okay = NULL; - if (@mysql_select_db($database)) { + if (@mysqli_select_db($conn, $database)) { $okay = "Database '$database' exists"; } elseif ($onlyRequire) { @@ -1247,8 +1247,8 @@ class InstallRequirements { return; } else { - $query = sprintf("CREATE DATABASE %s", mysql_real_escape_string($database)); - if (@mysql_query($query)) { + $query = sprintf("CREATE DATABASE %s", mysqli_real_escape_string($conn, $database)); + if (@mysqli_query($conn, $query)) { $okay = ts("Able to create a new database."); } else { @@ -1374,14 +1374,14 @@ class Installer extends InstallRequirements { * @param $database */ public function createDatabaseIfNotExists($server, $username, $password, $database) { - $conn = @mysql_connect($server, $username, $password); + $conn = @mysqli_connect($server, $username, $password); - if (@mysql_select_db($database)) { + if (@mysqli_select_db($conn, $database)) { // skip if database already present return; } - $query = sprintf("CREATE DATABASE %s", mysql_real_escape_string($database)); - if (@mysql_query($query)) { + $query = sprintf("CREATE DATABASE %s", mysqli_real_escape_string($conn, $database)); + if (@mysqli_query($conn, $query)) { } else { $errorTitle = ts("Oops! Could not create database %1", array(1 => $database)); diff --git a/sql/GenerateData.php b/sql/GenerateData.php index df0429b400..301e584e42 100644 --- a/sql/GenerateData.php +++ b/sql/GenerateData.php @@ -430,7 +430,7 @@ class CRM_GCD { private function _insert(&$dao) { if (self::ADD_TO_DB) { if (!$dao->insert()) { - echo "ERROR INSERT: " . mysql_error() . "\n"; + echo "ERROR INSERT: " . mysqli_error($dao->getConnection()->connection) . "\n"; print_r($dao); exit(1); } @@ -444,7 +444,7 @@ class CRM_GCD { private function _update(&$dao) { if (self::ADD_TO_DB) { if (!$dao->update()) { - echo "ERROR UPDATE: " . mysql_error() . "\n"; + echo "ERROR UPDATE: " . mysqli_error($dao->getConnection()->connection) . "\n"; print_r($dao); exit(1); } diff --git a/sql/GenerateReportData.php b/sql/GenerateReportData.php index 2f0d193947..fe5fbe3d7d 100644 --- a/sql/GenerateReportData.php +++ b/sql/GenerateReportData.php @@ -383,7 +383,7 @@ class CRM_GCD { private function _insert(&$dao) { if (self::ADD_TO_DB) { if (!$dao->insert()) { - echo "ERROR INSERT: " . mysql_error() . "\n"; + echo "ERROR INSERT: " . mysqli_error($dao->getConnection()->connection) . "\n"; print_r($dao); exit(1); } @@ -397,7 +397,7 @@ class CRM_GCD { private function _update($dao) { if (self::ADD_TO_DB) { if (!$dao->update()) { - echo "ERROR UPDATE: " . mysql_error() . "\n"; + echo "ERROR UPDATE: " . mysqli_error($dao->getConnection()->connection) . "\n"; print_r($dao); exit(1); } diff --git a/templates/CRM/common/civicrm.settings.php.template b/templates/CRM/common/civicrm.settings.php.template index dca7d99b8b..3425d90cf4 100644 --- a/templates/CRM/common/civicrm.settings.php.template +++ b/templates/CRM/common/civicrm.settings.php.template @@ -67,10 +67,10 @@ if (!defined('CIVICRM_UF')) { * * Update this setting with your CMS (Drupal, Backdrop CMS, or Joomla) database username, server and DB name. * Datasource (DSN) format: - * define( 'CIVICRM_UF_DSN', 'mysql://cms_db_username:cms_db_password@db_server/cms_database?new_link=true'); + * define( 'CIVICRM_UF_DSN', 'mysqli://cms_db_username:cms_db_password@db_server/cms_database?new_link=true'); */ if (!defined('CIVICRM_UF_DSN') && CIVICRM_UF !== 'UnitTests') { - define( 'CIVICRM_UF_DSN' , 'mysql://%%CMSdbUser%%:%%CMSdbPass%%@%%CMSdbHost%%/%%CMSdbName%%?new_link=true'); + define( 'CIVICRM_UF_DSN' , 'mysqli://%%CMSdbUser%%:%%CMSdbPass%%@%%CMSdbHost%%/%%CMSdbName%%?new_link=true'); } /** @@ -78,19 +78,19 @@ if (!defined('CIVICRM_UF_DSN') && CIVICRM_UF !== 'UnitTests') { * * Database URL (CIVICRM_DSN) for CiviCRM Data: * Database URL format: - * define( 'CIVICRM_DSN', 'mysql://crm_db_username:crm_db_password@db_server/crm_database?new_link=true'); + * define( 'CIVICRM_DSN', 'mysqli://crm_db_username:crm_db_password@db_server/crm_database?new_link=true'); * * Drupal and CiviCRM can share the same database, or can be installed into separate databases. * Backdrop CMS and CiviCRM can also share the same database, or can be installed into separate databases. * * EXAMPLE: Drupal/Backdrop and CiviCRM running in the same database... * DB Name = cms, DB User = cms - * define( 'CIVICRM_DSN' , 'mysql://cms:YOUR_PASSWORD@localhost/cms?new_link=true'); + * define( 'CIVICRM_DSN' , 'mysqli://cms:YOUR_PASSWORD@localhost/cms?new_link=true'); * * EXAMPLE: Drupal/Backdrop and CiviCRM running in separate databases... * CMS DB Name = cms, DB User = cms * CiviCRM DB Name = civicrm, CiviCRM DB User = civicrm - * define( 'CIVICRM_DSN' , 'mysql://civicrm:YOUR_PASSWORD@localhost/civicrm?new_link=true'); + * define( 'CIVICRM_DSN' , 'mysqli://civicrm:YOUR_PASSWORD@localhost/civicrm?new_link=true'); * */ if (!defined('CIVICRM_DSN')) { @@ -98,7 +98,7 @@ if (!defined('CIVICRM_DSN')) { define('CIVICRM_DSN', $GLOBALS['_CV']['TEST_DB_DSN']); } else { - define('CIVICRM_DSN', 'mysql://%%dbUser%%:%%dbPass%%@%%dbHost%%/%%dbName%%?new_link=true'); + define('CIVICRM_DSN', 'mysqli://%%dbUser%%:%%dbPass%%@%%dbHost%%/%%dbName%%?new_link=true'); } } diff --git a/tests/phpunit/CRM/Core/TransactionTest.php b/tests/phpunit/CRM/Core/TransactionTest.php index 2b32ca28dc..6b9de0353e 100644 --- a/tests/phpunit/CRM/Core/TransactionTest.php +++ b/tests/phpunit/CRM/Core/TransactionTest.php @@ -362,6 +362,7 @@ class CRM_Core_TransactionTest extends CiviUnitTestCase { if ($insert == 'sql-insert') { $r = CRM_Core_DAO::executeQuery("INSERT INTO civicrm_contact(first_name,last_name) VALUES ('ff', 'll')"); + // @fixme mysql_insert_id() does not exist in PHP7. $cid = mysql_insert_id(); } elseif ($insert == 'bao-create') {