Welcome Guest, Not a member yet? Register   Sign In
Bug : mysql_to_unix (PHP 7.4) and solution
#1
Bug 
(This post was last modified: 10-16-2022, 07:25 AM by lwmirkk.)

Hi!
I'm upgrading from CI 3.1.10 to 3.1.13 and from PHP 5.6 to 7.4
In future I will upgrade to CI 4 and PHP 8, but now this is faster and seems to be workng very well.
But: mysql_to_unix in PHP 5.6 if I use : 
2022-01-01 -> works as expected.
PHP 7.4 return nothing.
The solution is this:
From this original function in CI 3.1.13:
PHP Code:
function mysql_to_unix($time '')
 {
 
// We'll remove certain characters for backward compatibility
 // since the formatting changed with MySQL 4.1
 // YYYY-MM-DD HH:MM:SS

 
$time str_replace(array('-'':'' '), ''$time);

 
// YYYYMMDDHHMMSS
 
return mktime(
 
substr($time82),
 
substr($time102),
 
substr($time122),
 
substr($time42),
 
substr($time62),
 
substr($time04)
 );
 } 

To this one with NULL added, because if you do not have all parameters, substr() will return false in some args, but only NULL seems to be acceptable.
PHP Code:
return mktime(
 
substr($time82)?:null,
 
substr($time102)?:null,
 
substr($time122)?:null,
 
substr($time42)?:null,
 
substr($time62)?:null,
 
substr($time04)?:null
 
); 
Reply




Theme © iAndrew 2016 - Forum software by © MyBB