Search code examples
phpmysqlswoole

Class 'Swoole\MySQL' not found


Async Mysql Client of Swoole in my PHP Project for which I am trying to use Swoole MySQL Class of PHP but I am getting

class not found

error while executing the code.

Below is the code snippet I was trying to execute:

<?php

use Swoole\MySQL as MySQL;

MySQL::connect(array(
    'host'     => 'localhost',
    'port'     => '3306',
    'user'     => 'root',
    'password' => 'Secret_Password',
    'database' => 'swoole_test_db',
    'charset'  => 'utf8',
    'timeout'  => 2,
), function ($mysql_client) {
    $mysql_client->query("SELECT `reg_id`, `name` FROM `students` WHERE `reg_id` = 8;", function ($result) {
        var_dump($result);
    });
});

I tried searching everywhere but unable to find any reference on this error.

Version Details

  • PHP 7.3.2
  • Swoole Version 4.4.3 (with Swoole MySQL selected Yes during installation)

Swoole info from phpinfo()

Did I miss something, please help?

Thanks in advance!!!


Solution

  • It seems that the official documentation is either a bit off, or mentions a previous version of Swoole.

    The class that should be used is Swoole\Coroutine\MySQL.

    You can verify that using the official documentation in their GitHub repository.