Answers.Body: <p>I had the same error in <em>Drupal 7.56</em>:</p>
  
  <blockquote>
    <p><code>mysqli_real_escape_string()</code> expects parameter 1 to be <code>mysqli</code>, <code>null</code> given ...</p>
  </blockquote>
  
  <p>Exactly on line 1282 of the new <code>civicrm/install/index.php</code>, which is different from <em>CiviCRM 4.7.20</em>'s  <code>index.php</code>. So I just <strong>replaced the new file by the old one</strong> and all the checks became green and the installation proceeded normally (Drupal and CiviCRM share the same DB). CiviCRM is working fine.</p>
  
  <h1>Edit: after investigating...</h1>
  
  <p>I compared both versions <code>install/index.php</code> files and there is actually a new function that replaces all the connections to MySQL that were made previously and directly through <code>mysqli_connect($server, $username, $password)</code>.</p>
  
  <p>This is the new function:</p>
  
  <pre><code>protected function connect($host, $username, $password, $database = '') {
    $hostParts = explode(':', $host);
    if (count($hostParts) &gt; 1 &amp;&amp; strrpos($host, ']') !== strlen($host) - 1) {
      $port = array_pop($hostParts);
      $host = implode(':', $hostParts);
    }
    else {
      $port = '';
    }
    $conn = @mysqli_connect($host, $username, $password, $database, $port);
    return $conn;
  }
  </code></pre>
  
  <p>This function does not add or alter procedures in the installation process. It is basically a verification and treatment of the <code>$server</code> variable passed as parameter (<code>$host</code>). What it does:</p>
  
  <ol>
  <li>Does the <code>$server</code>/<code>$host</code> string contains a <strong>port</strong>?
  
  <ul>
  <li>if <strong>YES</strong> than:
  
  <ol>
  <li>pop it out from the string and place it under the <code>$port</code> variable;</li>
  <li>replace the original <code>$host</code> string by a new string without the port.</li>
  </ol></li>
  <li>if <strong>NO</strong> than: 
  
  <ol>
  <li>assign an empty string to <code>$port</code>.</li>
  </ol></li>
  </ul></li>
  <li><p>Establish a connection with the "new" separated parameters like so:</p>
  
  <pre><code>@mysqli_connect($host, $username, $password, $database, $port)
  </code></pre>
  
  <p>If you notice, the difference from the old version is just one: 2 more parameters provided to <code>mysqli_connect</code>, in order to support websites running in different ports.</p></li>
  </ol>
  
  <p>Which means, for all connections without a specific port (most cases), replacing <code>index.php</code> of version <em>4.7.21</em> with the one from version <em>4.7.20</em> will work (here's a <a href="https://pastebin.com/BrbTJx3j" rel="nofollow noreferrer">pastebin with the old <code>index.php</code></a>).</p>
  
  <h2>How to fix it in version 4.7.21</h2>
  
  <p>The problem does not lie in the <code>connect</code> function parameters treatment, but in <strong>the <code>$port</code> value, which if it becomes an empty string mysqli's result will be <code>null</code></strong>. Also the <code>$database</code> value is always empty.</p>
  
  <p>These can be fixed either by:</p>
  
  <ol>
  <li>adding the proper value to <code>$database</code> when <code>connect</code> is invoked</li>
  <li>providing a valid value for <code>$port</code> (not an empty string)</li>
  </ol>
  
  <h3>Quickfix (2.)</h3>
  
  <p>Do not allow the <code>$port</code> to become an empty string, i.e. replace <strong>only this line</strong> in the <code>install/index.php@connect</code>:</p>
  
  <pre><code>$port = '';
  </code></pre>
  
  <p>By this line:</p>
  
  <pre><code>$port = NULL;
  </code></pre>
  
  <p>This will prevent <code>mysqli_connect</code> result to be <code>null</code>.</p>
  
  <p>I have tested this in a new installation and it works.</p>
  
  <h3>Proper fix (1.):</h3>
  
  <p>For making use of the <code>$database</code> parameter, these lines:</p>
  
  <pre><code>$this-&gt;conn = $this-&gt;connect($server, $username, $password);
  </code></pre>
  
  <p>Must be replaced with:</p>
  
  <pre><code>$this-&gt;conn = $this-&gt;connect($server, $username, $password, $database);
  </code></pre>
  
  <p>These include lines 1040, 1075, 1105, 1145, 1226, 1270 and 1409.</p>
  
  <p>For the remaining lines (978 and 1192 where the <code>connect</code> is invoked), since there is no available database name value, we need to add to the respective functions the <code>$database</code> parameter, i.e.:</p>
  
  <ol>
  <li>For <code>requiredMysqlConnection</code>: 
  
  <ul>
  <li>replace with <code>public function requireMysqlConnection($server, $username, $password, $database, $testDetails) {</code></li>
  <li>replace with <code>$this-&gt;conn = $this-&gt;connect($server, $username, $password, $database);</code></li>
  <li>line 445 (after <code>$databaseConfig['password'],</code>) add a new line with <code>$databaseConfig['database'],</code> (<code>$dbName</code> should not be used since it only contains a default value like <code>'CiviCRM'</code>)</li>
  </ul></li>
  <li>For <code>requireMySQLAutoIncrementIncrementOne</code>:
  
  <ul>
  <li>replace with <code>public function requireMySQLAutoIncrementIncrementOne($server, $username, $password, $database, $testDetails) {</code></li>
  <li>replace with <code>$conn = $this-&gt;connect($server, $username, $password, $database);</code></li>
  <li>line 465 (after <code>$databaseConfig['password'],</code>) add a new line with <code>$databaseConfig['database'],</code> (<code>$dbName</code> should not be used since it only contains a default value like <code>'CiviCRM'</code>)</li>
  </ul></li>
  </ol>
  
  <p>This handles empty <code>$database</code> values. However, <strong>if <code>$port</code> is actually an empty string</strong>, <code>mysqli_connect</code> will also return <code>null</code>. Therefore, the line mentioned in the previous <strong>Quickfix (2.)</strong> should also be changed.</p>
  
  <p>I have tested this fix and it worked as well. If you have any suggestions/improvements, please comment below and I'll edit.</p>
  
Answers.ContentLicense: CC BY-SA 3.0
Answers.CreationDate: 2017-07-09T20:19:31.450Z
Answers.Text: Thanks for  the confirmation that it isn't me. Will stick with 4.7.20 and hope  that someone knowledgeable will explain and fix it.
Answers.UserDisplayName: Mick Kahn
Answers.ContentLicense: CC BY-SA 3.0
Answers.CreationDate: 2017-07-09T19:36:50.230Z
Answers.LastActivityDate: 2017-07-13T13:19:15.960Z
Answers.LastEditDate: 2017-07-13T13:19:15.960Z
Answers.UserDisplayName: Armfoot
Answers.Body: <p>This issue is corrected in the 4.7.22 release. I was able to do a clen install on a WordPress site. </p>
  
Answers.ContentLicense: CC BY-SA 3.0
Answers.CreationDate: 2017-07-13T21:53:23.587Z
Answers.Text: Yes version 4.7.22 seems to resolve this and I can get past the red screen... but I've now got another problem in that the menu doesn't show after completion of the install, but this is a different problem and as it now seems to be affecting an install of version 4.7.20 it is probably something that I've started doing wrong locally!
Answers.UserDisplayName: Mick Kahn
Answers.ContentLicense: CC BY-SA 3.0
Answers.CreationDate: 2017-07-13T13:21:43.807Z
Answers.LastActivityDate: 2017-07-13T13:21:43.807Z
Answers.UserDisplayName: KilakwaBT
Body: <p>Wanting to do a clean install of CiviCRM, I thought I should use version <em>4.7.21</em>. I am using a clean install of <em>WordPress 4.8</em> with no other plugins.</p>
  <p>I get the error message below when I go to the configure screen (<code>....&lt;civicrm directory&gt;/civicrm/install/index.php</code>) and all the database checks appear red (<em>edit</em>: attempted installation with <em>Drupal 7.56</em> with the exact same problem):</p>
  <blockquote>
  <p>Warning: <code>mysqli_real_escape_string()</code> expects parameter 1 to be <code>mysqli</code>, <code>null</code> given in <code>/home/fotgm080/public_html/temp2/wp-content/plugins/civicrm/civicrm/install/index.php</code> on line 1282</p>
  <p>Your database settings don't appear to be correct.</p>
  <ul>
  <li><p>Does the server exist?  OK (localhost)</p>
  </li>
  <li><p>Are the access credentials correct? That username/password doesn't work:</p>
  </li>
  <li><p>Can I access/create the database?   I can't create new databases and the database 'fotgm080_wp685' doesn't exist. (user 'fotgm080_wp685' doesn't have CREATE DATABASE permissions.)</p>
  </li>
  <li><p>Can I access/create InnoDB tables in the database?  Unable to create InnoDB tables. MySQL InnoDB support is required for CiviCRM but is either not available or not enabled in this MySQL database server. Could not determine if MySQL has InnoDB support. Assuming no.</p>
  </li>
  <li><p>Can I create temporary tables in the database?  Could not login to the database.</p>
  </li>
  <li><p>Can I create lock tables in the database?   Could not connect to the database server.</p>
  </li>
  <li><p>Can I create triggers in the database?  Could not login to the database.</p>
  </li>
  </ul>
  </blockquote>
  <p>If I do a clean install of WordPress/Drupal again and try <em>CiviCRM 4.7.20</em> then everything is fine.</p>
  
Comments.ContentLicense: CC BY-SA 3.0
Comments.CreationDate: 2017-07-09T14:52:07.090Z
Comments.Text: Hi Mick, I encountered the same problem with 4.7.21 version. After we found the error message in our logs, we decided to delete all files and installed 4.7.20 version, instead. It installed just fine.
  
  wget http://sourceforge.net/projects/civicrm/files/civicrm-stable/4.7.20/civicrm-4.7.20-wordpress.zip
Comments.UserDisplayName: Birgit Pauli-Haack
Comments.ContentLicense: CC BY-SA 3.0
Comments.CreationDate: 2017-07-10T02:23:40.497Z
Comments.Text: Just another chime in that my Wordpress set up did the exact same thing - thanksumundo for this post, saved a lot of hair pulling.
Comments.UserDisplayName: RayWright
Comments.ContentLicense: CC BY-SA 3.0
Comments.CreationDate: 2017-07-10T14:32:43.800Z
Comments.Text: Has anyone made a ticket in JIRA yet? I can't find anything... Thanks!
Comments.UserDisplayName: David Snopek
Comments.ContentLicense: CC BY-SA 3.0
Comments.CreationDate: 2017-07-17T16:27:35.113Z
Comments.Text: Here's the JIRA ticket: https://issues.civicrm.org/jira/browse/CRM-20829
Comments.UserDisplayName: David Snopek
Tags: <wordpress><drupal><installation><version>
Title: Cannot install CiviCRM 4.7.21 on WordPress/Drupal
ThreadText: # Cannot install CiviCRM 4.7.21 on WordPress/Drupal
  
  (Asked by: username_0 on 2017-07-07)
  
  Wanting to do a clean install of CiviCRM, I thought I should use version *4.7.21*. I am using a clean install of *WordPress 4.8* with no other plugins.
  
  I get the error message below when I go to the configure screen (`....<civicrm directory>/civicrm/install/index.php`) and all the database checks appear red (*edit*: attempted installation with *Drupal 7.56* with the exact same problem):
  
  > Warning: `mysqli_real_escape_string()` expects parameter 1 to be `mysqli`, `null` given in `/home/fotgm080/public_html/temp2/wp-content/plugins/civicrm/civicrm/install/index.php` on line 1282
  >
  > Your database settings don't appear to be correct.
  >
  > * Does the server exist? OK (localhost)
  > * Are the access credentials correct? That username/password doesn't work:
  > * Can I access/create the database? I can't create new databases and the database 'fotgm080\_wp685' doesn't exist. (user 'fotgm080\_wp685' doesn't have CREATE DATABASE permissions.)
  > * Can I access/create InnoDB tables in the database? Unable to create InnoDB tables. MySQL InnoDB support is required for CiviCRM but is either not available or not enabled in this MySQL database server. Could not determine if MySQL has InnoDB support. Assuming no.
  > * Can I create temporary tables in the database? Could not login to the database.
  > * Can I create lock tables in the database? Could not connect to the database server.
  > * Can I create triggers in the database? Could not login to the database.
  
  If I do a clean install of WordPress/Drupal again and try *CiviCRM 4.7.20* then everything is fine.
  
  **Tags:** wordpress, drupal, installation, version
  
  > **Comments:**
  > **username_1**: Hi username_0, I encountered the same problem with 4.7.21 version. After we found the error message in our logs, we decided to delete all files and installed 4.7.20 version, instead. It installed just fine.  wget http://sourceforge.net/projects/civicrm/files/civicrm-stable/4.7.20/civicrm-4.7.20-wordpress.zip  
  > **username_2**: Just another chime in that my Wordpress set up did the exact same thing - thanksumundo for this post, saved a lot of hair pulling.  
  > **username_3**: Has anyone made a ticket in JIRA yet? I can't find anything... Thanks!  
  > **username_3**: Here's the JIRA ticket: https://issues.civicrm.org/jira/browse/CRM-20829  
  
  ---
  
  ## 2 answers
  
  ### Answer by username_5 on 2017-07-13. Score: 3 | Accepted answer
  
  This issue is corrected in the 4.7.22 release. I was able to do a clen install on a WordPress site.
  
  > **Comments:**
  > **username_0**: Yes version 4.7.22 seems to resolve this and I can get past the red screen... but I've now got another problem in that the menu doesn't show after completion of the install, but this is a different problem and as it now seems to be affecting an install of version 4.7.20 it is probably something that I've started doing wrong locally!  
  
  ---
  
  ### Answer by username_4 on 2017-07-09. Score: 2
  
  I had the same error in *Drupal 7.56*:
  
  > `mysqli_real_escape_string()` expects parameter 1 to be `mysqli`, `null` given ...
  
  Exactly on line 1282 of the new `civicrm/install/index.php`, which is different from *CiviCRM 4.7.20*'s `index.php`. So I just **replaced the new file by the old one** and all the checks became green and the installation proceeded normally (Drupal and CiviCRM share the same DB). CiviCRM is working fine.
  
  # Edit: after investigating...
  
  I compared both versions `install/index.php` files and there is actually a new function that replaces all the connections to MySQL that were made previously and directly through `mysqli_connect($server, $username, $password)`.
  
  This is the new function:
  
  ```
  protected function connect($host, $username, $password, $database = '') {
    $hostParts = explode(':', $host);
    if (count($hostParts) > 1 && strrpos($host, ']') !== strlen($host) - 1) {
      $port = array_pop($hostParts);
      $host = implode(':', $hostParts);
    }
    else {
      $port = '';
    }
    $conn = @mysqli_connect($host, $username, $password, $database, $port);
    return $conn;
  }
  
  ```
  
  This function does not add or alter procedures in the installation process. It is basically a verification and treatment of the `$server` variable passed as parameter (`$host`). What it does:
  
  1. Does the `$server`/`$host` string contains a **port**?
     * if **YES** than:
       1. pop it out from the string and place it under the `$port` variable;
       2. replace the original `$host` string by a new string without the port.
     * if **NO** than:
       1. assign an empty string to `$port`.
  2. Establish a connection with the "new" separated parameters like so:
  
     ```
     @mysqli_connect($host, $username, $password, $database, $port)
  
     ```
  
     If you notice, the difference from the old version is just one: 2 more parameters provided to `mysqli_connect`, in order to support websites running in different ports.
  
  Which means, for all connections without a specific port (most cases), replacing `index.php` of version *4.7.21* with the one from version *4.7.20* will work (here's a [pastebin with the old `index.php`](https://pastebin.com/BrbTJx3j)).
  
  ## How to fix it in version 4.7.21
  
  The problem does not lie in the `connect` function parameters treatment, but in **the `$port` value, which if it becomes an empty string mysqli's result will be `null`**. Also the `$database` value is always empty.
  
  These can be fixed either by:
  
  1. adding the proper value to `$database` when `connect` is invoked
  2. providing a valid value for `$port` (not an empty string)
  
  ### Quickfix (2.)
  
  Do not allow the `$port` to become an empty string, i.e. replace **only this line** in the `install/index.php@connect`:
  
  ```
  $port = '';
  
  ```
  
  By this line:
  
  ```
  $port = NULL;
  
  ```
  
  This will prevent `mysqli_connect` result to be `null`.
  
  I have tested this in a new installation and it works.
  
  ### Proper fix (1.):
  
  For making use of the `$database` parameter, these lines:
  
  ```
  $this->conn = $this->connect($server, $username, $password);
  
  ```
  
  Must be replaced with:
  
  ```
  $this->conn = $this->connect($server, $username, $password, $database);
  
  ```
  
  These include lines 1040, 1075, 1105, 1145, 1226, 1270 and 1409.
  
  For the remaining lines (978 and 1192 where the `connect` is invoked), since there is no available database name value, we need to add to the respective functions the `$database` parameter, i.e.:
  
  1. For `requiredMysqlConnection`:
     * replace with `public function requireMysqlConnection($server, $username, $password, $database, $testDetails) {`
     * replace with `$this->conn = $this->connect($server, $username, $password, $database);`
     * line 445 (after `$databaseConfig['password'],`) add a new line with `$databaseConfig['database'],` (`$dbName` should not be used since it only contains a default value like `'CiviCRM'`)
  2. For `requireMySQLAutoIncrementIncrementOne`:
     * replace with `public function requireMySQLAutoIncrementIncrementOne($server, $username, $password, $database, $testDetails) {`
     * replace with `$conn = $this->connect($server, $username, $password, $database);`
     * line 465 (after `$databaseConfig['password'],`) add a new line with `$databaseConfig['database'],` (`$dbName` should not be used since it only contains a default value like `'CiviCRM'`)
  
  This handles empty `$database` values. However, **if `$port` is actually an empty string**, `mysqli_connect` will also return `null`. Therefore, the line mentioned in the previous **Quickfix (2.)** should also be changed.
  
  I have tested this fix and it worked as well. If you have any suggestions/improvements, please comment below and I'll edit.
  
  > **Comments:**
  > **username_0**: Thanks for  the confirmation that it isn't me. Will stick with 4.7.20 and hope  that someone knowledgeable will explain and fix it.  
  
  ---
  
  