CodeIgniter Forums
getting error because of using php 7.2? - Printable Version

+- CodeIgniter Forums (https://forum.codeigniter.com)
+-- Forum: Using CodeIgniter (https://forum.codeigniter.com/forumdisplay.php?fid=5)
+--- Forum: Libraries & Helpers (https://forum.codeigniter.com/forumdisplay.php?fid=11)
+--- Thread: getting error because of using php 7.2? (/showthread.php?tid=74795)



getting error because of using php 7.2? - richb201 - 11-07-2019

I have moved my app from php 5.6 to php 7.2 because the dockerized version with xdebug was only avail in 7.2. Anyhow, I am getting this strange error. Is this due to the change from php 5.6 or due to some path error for the database or some problem with CI 3.11 and php 7.2? What should I look at first?


[docker://bitnami/php-fpm7:latest/]:php /opt/docker-substantiator/app/index.php

A PHP Error was encountered

Severity:    Warning
Message:    mysqli::real_connect(): (HY000/2002): Connection refused
Filename:    /opt/docker-substantiator/app/system/database/drivers/mysqli/mysqli_driver.php
Line Number: 201

Backtrace:
File: /opt/docker-substantiator/app/application/core/MY_Loader.php
Line: 277
Function: database

File: /opt/docker-substantiator/app/application/controllers/Users.php
Line: 15
Function: __construct

File: /opt/docker-substantiator/app/index.php
Line: 317
Function: require_once



Database error: A Database Error Occurred

Unable to connect to your database server using the provided settings.
Filename: controllers/Users.php
Line Number: 15


Process finished with exit code 8

Now if I go look at line 15  in Users.php I see:

function __construct() {
    parent::__construct();     << line 15
    $this->load->library('form_validation');
    $this->load->library('session');
    $this->load->model('User');
    $this->load->helper(array('form', 'url'));
    $this->load->database();
    $this->_init();

}



RE: getting error because of using php 7.2? - InsiteFX - 11-07-2019

It's saying that your database settings are wrong.

If the php 7.2 you installed also installed MySQL then it must have changed
your MySQL password etc;


RE: getting error because of using php 7.2? - richb201 - 11-07-2019

I can see that. But what is strange is that when I don't go through phpStorm and type localhost directly into the browser, it works fine. How can that be? Perhaps in that case it is using the mySQL that is not in the docker container?


RE: getting error because of using php 7.2? - InsiteFX - 11-07-2019

Or phpStorm is not finding it through it's database config.

Check the phpStorm database settings.


RE: getting error because of using php 7.2? - richb201 - 11-08-2019

I contacted the phpStorm support team. They stated that there is nowhere in phpStorm where I would set this. Here is the error I am getting:

Severity:    Warning
Message:    CI_DB_mysqli_driver::db_connect(): Property access is not allowed yet
Filename:    /opt/docker-substantiator/app/system/database/drivers/mysqli/mysqli_driver.php
Line Number: 201


Backtrace:
File: /opt/docker-substantiator/app/application/core/MY_Loader.php
Line: 277
Function: database

File: /opt/docker-substantiator/app/application/controllers/Users.php
Line: 15
Function: __construct

File: /opt/docker-substantiator/app/index.php
Line: 317
Function: require_once

I get about 7 or 8 of this same exact error, and the  finally I get to this line:
if ($this->_mysqli->real_connect($hostname, $this->username, $this->password, $this->database, $port, $socket, $client_flags))
which has this comment right below it:
// Prior to version 5.7.3, MySQL silently downgrades to an unencrypted connection if SSL setup fails

and this line fails with this error:

Database error: A Database Error Occurred



Unable to connect to your database server using the provided settings.

Filename: controllers/Users.php

Line Number: 15




Process finished with exit code 8


RE: getting error because of using php 7.2? - richb201 - 12-09-2019

(11-08-2019, 06:30 AM)richb201 Wrote: I contacted the phpStorm support team. They stated that there is nowhere in phpStorm where I would set this. Here is the error I am getting:

Severity:    Warning
Message:    CI_DB_mysqli_driver::db_connect(): Property access is not allowed yet
Filename:    /opt/docker-substantiator/app/system/database/drivers/mysqli/mysqli_driver.php
Line Number: 201


Backtrace:
File: /opt/docker-substantiator/app/application/core/MY_Loader.php
Line: 277
Function: database

File: /opt/docker-substantiator/app/application/controllers/Users.php
Line: 15
Function: __construct

File: /opt/docker-substantiator/app/index.php
Line: 317
Function: require_once

I get about 7 or 8 of this same exact error, and the  finally I get to this line:
if ($this->_mysqli->real_connect($hostname, $this->username, $this->password, $this->database, $port, $socket, $client_flags))
which has this comment right below it:
// Prior to version 5.7.3, MySQL silently downgrades to an unencrypted connection if SSL setup fails

and this line fails with this error:

Database error: A Database Error Occurred



Unable to connect to your database server using the provided settings.

Filename: controllers/Users.php

Line Number: 15




Process finished with exit code 8

NOTE: I managed to solve this. I think the issue was with the Docker version of mySQL. 



RE: getting error because of using php 7.2? - John_Betong - 12-09-2019

Here are two CodeIgniter4 declare(strict_types=1); modifications that may be relevant.

The changes were necessary to connect to the MySQLi database:

file: system/Database/Query.php
PHP Code:
public function getStartTime(bool $returnRaw falseint $decimals 6): string
{
  if ($returnRaw)
  {
    # JOHN MODIFIED
    # return $this->startTime;
    return number_format($this->startTime$decimals);
  }

  return number_format($this->startTime$decimals);


file: system/Database/MySQLi/Connection.php
Code:
public function connect(bool $persistent = false)
{
// Do we have a socket path?
if ($this->hostname[0] === '/')
{
  $hostname = null;
  $port     = null;
  $socket   = $this->hostname;
}
else
{
  $hostname = ($persistent === true) ? 'p:' . $this->hostname : $this->hostname;
  $port     = empty($this->port) ? null : $this->port;
  # JOHN MODIFIED
  # $socket = null;
  $socket   = '';
}