Giter VIP home page Giter VIP logo

Comments (6)

Yurunsoft avatar Yurunsoft commented on July 25, 2024

是用的 Swoole\Coroutine\MySQL 吗?这个已经不推荐使用了

from swoole-src.

kiss291323003 avatar kiss291323003 commented on July 25, 2024

和推荐不推荐没关系、这意味着整个4.x到5.x都有bug。这线上用的咋办

from swoole-src.

Yurunsoft avatar Yurunsoft commented on July 25, 2024

无法复现

代码:

<?php

declare(strict_types=1);

use Swoole\Coroutine\MySQL;

// mysqli
$mysqli = new \mysqli('127.0.0.1', 'root', 'root', 'swoole');
$mysqli->query('TRUNCATE student_score');
$stmt = $mysqli->prepare('INSERT  INTO `student_score` (`scoreId`, `studentId`, `courseId`, `score`)  VALUES (?, ?, ?, ?) ON DUPLICATE KEY UPDATE `score` = ?');
$stmt->execute([1,1,1,1,1]);
var_dump($stmt->insert_id, $stmt->affected_rows);
$stmt->execute([1,1,1,1,1]);
var_dump($stmt->insert_id, $stmt->affected_rows);

// swoole
Co\run(function(){
    $mysql = new MySQL();
    $mysql->connect([
        'host'     => '127.0.0.1',
        'port'     => 3306,
        'user'     => 'root',
        'password' => 'root',
        'database' => 'swoole',
    ]);
    $mysql->query('TRUNCATE student_score');
    $stmt = $mysql->prepare('INSERT  INTO `student_score` (`scoreId`, `studentId`, `courseId`, `score`)  VALUES (?, ?, ?, ?) ON DUPLICATE KEY UPDATE `score` = ?');
    $stmt->execute([1,1,1,1,1]);
    var_dump($stmt->insert_id, $stmt->affected_rows);
    $stmt->execute([1,1,1,1,1]);
    var_dump($stmt->insert_id, $stmt->affected_rows);
});

结果:

# php test.php
int(1)
int(1)
int(0)
int(0)
int(1)
int(1)
int(0)
int(0)

from swoole-src.

kiss291323003 avatar kiss291323003 commented on July 25, 2024

重新测试中

from swoole-src.

kiss291323003 avatar kiss291323003 commented on July 25, 2024
//swoole mysql
$ret = $stmt->execute([1,1,1,time(),1]);
  var_dump($ret);
  $ret = $stmt->execute([1,1,1,time(),1]);
  var_dump($ret);
  var_dump($stmt->fetchAll());
// mysqli
$ret = $stmt->execute([1,1,1,1,1]);
var_dump($stmt->get_result());
$stmt = $mysqli->prepare('INSERT  INTO `student_score` (`scoreId`, `studentId`, `courseId`, `score`)  VALUES (?, ?, ?, ?) ON DUPLICATE KEY UPDATE `score` = ?');
$ret = $stmt->execute([1,1,1,time(),1]);
var_dump($stmt->get_result());

mysqli的返回是false,swoole的都是true。id那个我换了环境好了

from swoole-src.

Yurunsoft avatar Yurunsoft commented on July 25, 2024

这边测试 execute() 返回值都是 true

mysqli 的 get_result() 返回 false
swoole 的 fetchAll() 返回空数组
框架层面做好兼容就行了

from swoole-src.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.