Skip to content

fix #115 for mysql 8.4.0 #116

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

Open
wants to merge 12 commits into
base: master
Choose a base branch
from
Open

fix #115 for mysql 8.4.0 #116

wants to merge 12 commits into from

Conversation

hetao29
Copy link
Contributor

@hetao29 hetao29 commented May 5, 2024

No description provided.

@hetao29 hetao29 changed the title fix #115 for mysql 8.0.0 fix #115 for mysql 8.4.0 May 5, 2024
@krowinski krowinski self-assigned this May 8, 2024
Copy link
Owner

@krowinski krowinski left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

hi tx for contribution

1, Fix tests

  1. MySQLReplication\Tests\Unit\Repository\MySQLRepositoryTest::testShouldGetVersion
    Failed asserting that two strings are equal.
    --- Expected
    +++ Actual
    @@ @@
    -'foobar123'
    +''

run composer cs:fix to fix code style

@hetao29 hetao29 requested a review from krowinski May 8, 2024 09:52
@cyppe
Copy link
Contributor

cyppe commented Nov 18, 2024

Any status of this PR or is there some other php 8.4 fixes in the works?

@hetao29
Copy link
Contributor Author

hetao29 commented Nov 18, 2024

Any status of this PR or is there some other php 8.4 fixes in the works?

My project used this pr in product env.

@cyppe
Copy link
Contributor

cyppe commented Apr 19, 2025

@krowinski now with more mysql versions in test suite, maybe this has a chance to be tested and (maybe) merged?

@krowinski
Copy link
Owner

@cyppe resolve conflict pls

@krowinski
Copy link
Owner

tests are failing

There were 2 failures:

  1. MySQLReplication\Tests\Unit\BinaryDataReader\BinaryDataReaderTest::testShouldReadInt64
    Failed asserting that -72057589759737856 is identical to '-72057589759737856'.

/home/runner/work/php-mysql-replication/php-mysql-replication/tests/Unit/BinaryDataReader/BinaryDataReaderTest.php:138

  1. MySQLReplication\Tests\Unit\BinaryDataReader\BinaryDataReaderTest::testShouldPack64bit
    Failed asserting that 9223372036854775807 is identical to '9223372036854775807'.

/home/runner/work/php-mysql-replication/php-mysql-replication/tests/Unit/BinaryDataReader/BinaryDataReaderTest.php:190

FAILURES!
Tests: 131, Assertions: 666, Failures: 2.

@hetao29
Copy link
Contributor Author

hetao29 commented Apr 24, 2025

tests are failing

There were 2 failures:

  1. MySQLReplication\Tests\Unit\BinaryDataReader\BinaryDataReaderTest::testShouldReadInt64
    Failed asserting that -72057589759737856 is identical to '-72057589759737856'.

/home/runner/work/php-mysql-replication/php-mysql-replication/tests/Unit/BinaryDataReader/BinaryDataReaderTest.php:138

  1. MySQLReplication\Tests\Unit\BinaryDataReader\BinaryDataReaderTest::testShouldPack64bit
    Failed asserting that 9223372036854775807 is identical to '9223372036854775807'.

/home/runner/work/php-mysql-replication/php-mysql-replication/tests/Unit/BinaryDataReader/BinaryDataReaderTest.php:190

FAILURES! Tests: 131, Assertions: 666, Failures: 2.

Because I change return value of Int64 type like default PDO::ATTR_STRINGIFY_FETCHES=false OR MYSQLI_OPT_INT_AND_FLOAT_NATIVE , Int64 may string or int value.

CREATE TABLE `test` (
  `id` bigint unsigned NOT NULL DEFAULT '0',
  `show` int DEFAULT NULL,
  PRIMARY KEY (`id`)
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_0900_ai_ci;
insert into test(id) values(9223372036854775807),(9223372036854775808);
try {
// 数据库配置
$host = '127.0.0.1';
$db   = 'test';    // 你的数据库名
$user = 'root';       // 数据库用户名
$pass = '';           // 数据库密码
$port = "3306";
$charset = 'utf8mb4';

// 设置DSN(数据源名称)
$dsn = "mysql:host=$host;dbname=$db;charset=$charset;port=$port";

// 设置PDO选项
$options = [
    PDO::ATTR_ERRMODE            => PDO::ERRMODE_EXCEPTION, // 抛出异常错误
    PDO::ATTR_DEFAULT_FETCH_MODE => PDO::FETCH_ASSOC,       // 获取关联数组
    PDO::ATTR_EMULATE_PREPARES   => false,                  // 关闭模拟预处理
];
    // 创建PDO实例
    $pdo = new PDO($dsn, $user, $pass, $options);

    // 编写SQL语句
    $sql = "SELECT * FROM test"; // 假设你有一个users表
    var_dump(PHP_INT_MAX);
    var_dump(PHP_INT_MIN);

    // 执行查询
    $stmt = $pdo->query($sql);

    // 获取结果
    while ($row = $stmt->fetch()) {
        var_dump($row);
    }

} catch (\PDOException $e) {
    // 处理连接错误
    throw new \PDOException($e->getMessage(), (int)$e->getCode());
}

Comment on lines +127 to +131
if($num>PHP_INT_MAX || $num<PHP_INT_MIN){
return $num;
}else{
return intval($num);
}
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Its better to return always string here

Copy link
Contributor Author

@hetao29 hetao29 Apr 26, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The PDO or MysqlNd default return string( big than PHP_INT_MAX) and int(less than PHP_INT_MIN) ,but in the end, you decide.

image

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looks like you are really close to getting this done, @krowinski maybe you can be the tie breaker and just say how you want it to get this rolling? Would be awesome to get Mysql 8.4 support rolling.

Comment on lines +150 to +155
$num = bcadd((string)$data[1], (string)($data[2] << 32));
if($num>PHP_INT_MAX || $num<PHP_INT_MIN){
return $num;
}else{
return intval($num);
}
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

same here

@krowinski krowinski self-requested a review May 5, 2025 17:23
@hetao29
Copy link
Contributor Author

hetao29 commented May 19, 2025

At present, the main problem is that there are some problems with the test cases in tests. I have taken a look at it and it is quite complicated. I would like to ask you to solve it~~

cyppe added a commit to cyppe/php-mysql-replication that referenced this pull request Jun 22, 2025
…Int64

- Changed readInt64() to always return string instead of string|int
- Changed unpackUInt64() to always return string instead of string|int
- Changed readUInt64() return type to string for consistency
- Applied code style fixes with composer cs:fix
- Fixes failing tests: testShouldReadInt64 and testShouldPack64bit

Addresses maintainer feedback from PR krowinski#116 regarding MySQL 8.4.0 compatibility.
krowinski pushed a commit that referenced this pull request Jun 25, 2025
* fix #115 for mysql 8.0.0

* fix #115 for mysql 8.4.0

* fix #115 for mysql 8.4.0 phpunit test

* fix issue #125

* change to hetao29

* Fix PHP 8.4 deprecation: Implicitly marking parameter as nullable is deprecated, the explicit nullable type must be used instead

* change to krowinski

* Fix maintainer feedback: always return strings from readInt64/unpackUInt64

- Changed readInt64() to always return string instead of string|int
- Changed unpackUInt64() to always return string instead of string|int
- Changed readUInt64() return type to string for consistency
- Applied code style fixes with composer cs:fix
- Fixes failing tests: testShouldReadInt64 and testShouldPack64bit

Addresses maintainer feedback from PR #116 regarding MySQL 8.4.0 compatibility.

* Fix DBAL 4.x compatibility issue in testShouldReconnect

In DBAL 4.x, Doctrine\DBAL\Exception became an interface instead of a concrete class.
The test was trying to instantiate 'new Exception('')' which fails with
'Cannot instantiate interface Doctrine\DBAL\Exception'.

Fixed by using ConnectionException mock which implements the Exception interface,
preserving the exact same test logic and coverage as the original DBAL 3.x version.

* Fix MySQLRepository for DBAL 4.x compatibility

Remove manual connection reconnection logic since DBAL 4.x handles
reconnection automatically. The connect() method became protected
in DBAL 4.x, causing 'Call to protected method' errors.

Changes:
- Removed manual ping/close/connect logic from getConnection()
- DBAL 4.x automatically handles lost connections and reconnection
- Kept ping() method as required by PingableConnection interface

This fixes the repository to work with DBAL 4.x while maintaining
the same functionality.

---------

Co-authored-by: hetao <hetao@hetao.name>
Co-authored-by: HeTao <8010298+hetao29@users.noreply.github.com>
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

Successfully merging this pull request may close these issues.

3 participants