Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

PHP8.1 compatibility issue on logging null #374

Open
howan4work opened this issue Dec 12, 2022 · 0 comments
Open

PHP8.1 compatibility issue on logging null #374

howan4work opened this issue Dec 12, 2022 · 0 comments

Comments

@howan4work
Copy link

howan4work commented Dec 12, 2022

Version: v1.5.8

Output Deprecated: PDO::quote(): Passing null to parameter #1 ($string) of type string is deprecated in C:\VHOST\VHOST8\idiorm\vendor\j4mie\idiorm\idiorm.php on line 539

Testing Code

<?php
declare(strict_types=1);
require_once "vendor/autoload.php";
date_default_timezone_set('Asia/Hong_Kong');
ini_set("assert.exception", "1");
//error_reporting(E_ALL & ~E_DEPRECATED);

/*
CREATE TABLE `testing` (
	`id` INT(11) NOT NULL AUTO_INCREMENT,
	`timestamp` DATETIME NULL DEFAULT current_timestamp() ON UPDATE current_timestamp(),
	PRIMARY KEY (`id`) USING BTREE
) COLLATE='utf8_general_ci' ENGINE=InnoDB;
*/
try{
    $hFile = fopen(__DIR__.DIRECTORY_SEPARATOR."run.log", 'w');
    $writeLine = function(string $message) use ($hFile):void{
        fwrite($hFile, $message.PHP_EOL);
    };
    $arrConfig = [
        'connection_string'=>'mysql:host=localhost;dbname=temp',
        'username'=>'root',
        'password'=>'P@ssw0rd',
        'return_result_sets'=>TRUE,
        'driver_options'=>[PDO::MYSQL_ATTR_INIT_COMMAND => 'SET NAMES utf8'],
        'error_mode'=>PDO::ERRMODE_EXCEPTION,
        'logging' => TRUE,
        'logger' => function($query, $time) use ($writeLine):void{
            $log = sprintf("[SQL %07.3f] %s", $time, $query);
            $writeLine($log);
        },
    ];
    ORM::configure($arrConfig);
    $orm = ORM::forTable("testing")->create();
    if(!$orm->save()) $writeLine("Create Fails");
    $id = intval($orm->id);
    $orm = ORM::forTable("testing")->findOne($id);
    $writeLine("Id# {$id} and get ".($orm->timestamp??"<NULL>"));
    $orm->timestamp = '2022-12-12 12:12:12';
    $orm->save();
    $writeLine("Id# {$id} and get ".($orm->timestamp??"<NULL>"));
    $orm->timestamp = NULL;
    $orm->save();
    $writeLine("Id# {$id} and get ".($orm->timestamp??"<NULL>"));
    if($hFile) fclose($hFile);
} catch (Throwable $ex){
    $writeLine("[Throwable] ".$ex->getMessage());
    if($hFile) fclose($hFile);
}

Beside the notice, the logged SQL is not correct.
[SQL 000.007] UPDATE testingSETtimestamp= '' WHEREid = '8'

@howan4work howan4work changed the title PHP8.1 compatibility issue on _log_query PHP8.1 compatibility issue on logging null Dec 19, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant