amphp / mysql

An async MySQL client for PHP, optimizing database interactions with efficient non-blocking capabilities. Perfect for responsive, high-performance applications.
Other
358 stars 63 forks source link

Problem with receiving all rows #64

Closed sallsabil closed 6 years ago

sallsabil commented 6 years ago

Hello My table has 3504 rows. When I use this code:

    function resultToArray($result) {
    $rows = array();
    while($row = mysqli_fetch_assoc($result)) {
        $rows[] = $row;
    }
    return $rows;
    }

    function GetMyConnectionGroup() {
        $servername = 'localhost';
        $username = 'root';
        $password = '******';
        $dbname = 'dbn';
        global $g_link;
        if ($g_link) return $g_link;
        $g_link = new mysqli($servername, $username, $password, $dbname) or die('Could not connect to server.');
        return $g_link;
        }

        $res = mysqli_query(GetMyConnectionGroup() , "SELECT * FROM groups ORDER BY id");
        $rows = resultToArray($res);
        mysqli_free_result($res);

I can receive all of 3504 rows But when I use this code:

function MGSC($code='', $m=0) {
    global $row;
    global $db;
\Amp\Loop::run(function() use ($code, $row, $db, $m) {
    global $row;
    global $db;
    if($code) {
    if(!$db) $db = Amp\Mysql\pool("host=localhost user=root password=***** db=dbn");

    $type = explode(' ', $code, 2);
    $type[0] = strtolower($type[0]);
    $result = yield $db->query($code);
    if($type[0] == 'select') {
    $row = [];
    if($m === 0) {
    while (yield $result->advance()) {
        $row = $result->getCurrent();
    }
    }
    elseif($m === 1) {
    while (yield $result->advance()) {
        $row[] = $result->getCurrent();
    }
    }
    return $row;
    }
    else {
    return $result;
    }
    }
    else {
    if($db) $db->close();
    }
});
    if($code) {if($row) return $row; elseif(isset($result)) return $result;}
        }

$rows = MGSC("SELECT * FROM groups ORDER BY id", 1);

I mostly receive just 4 rows and some times 25 rows. Also these errors:

2018-02-07T16:34:01.942293Z 215 [Note] Aborted connection 215 to db: 'dbn' user: 'root' host: 'localhost' (Got an error writing communication packets)

2018-02-07T15:48:02.011128Z 169 [Note] Aborted connection 169 to db: 'dbn' user: 'root' host: 'localhost' (Got an error reading communication packets)

How can I receive all rows ? What is the problem ?

sallsabil commented 6 years ago

I'm waiting for you. If there is no solution Please tell me to switch to the last one. Thank you @trowski @bwoebi

bwoebi commented 6 years ago

I cannot reproduce that problem locally. May you please set const MYSQL_DEBUG = true; and dump me the data, so that I can replay and debug your connection?

Thanks :-)

sallsabil commented 6 years ago

I sent you the error:

2018-02-07T16:34:01.942293Z 215 [Note] Aborted connection 215 to db: 'dbn' user: 'root' host: 'localhost' (Got an error writing communication packets)

2018-02-07T15:48:02.011128Z 169 [Note] Aborted connection 169 to db: 'dbn' user: 'root' host: 'localhost' (Got an error reading communication packets)

There is not any other error

bwoebi commented 6 years ago

I mean within your script. with define("MYSQL_DEBUG", true); it should dump all the raw protocol data to the stderr of your script.

sallsabil commented 6 years ago

I did what you said but I received nothing other than:

2018-02-12T09:00:01.855322Z 6888 [Note] Aborted connection 6888 to db: 'groupbots' user: 'root' host: 'localhost' (Got an error reading communication packets)

sallsabil commented 6 years ago

I think the problem is from your project

sallsabil commented 6 years ago

Am I right ?

trowski commented 6 years ago

@sallsabil We may have a bug in our protocol implementation, but we cannot reproduce it ourselves. Please add const MYSQL_DEBUG = true; to your script, perhaps right after the autoload script is included. This will cause information about the raw protocol to be written to STDERR. If you're using a web SAPI, you may need to check the error log for this information, otherwise it should just be written to the console.

sallsabil commented 6 years ago
<?php
    $start = microtime(true);
    set_time_limit(62);
    require "/root/vendor/autoload.php";
    const MYSQL_DEBUG = true;
    require __DIR__ . '/classes/setexpf.php';
    $setexpf = new setexpf();

    $rows = $setexpf->MGSC("SELECT * FROM groups ORDER BY id", 1);
    echo count($rows);

I use ubuntu 16.04 but in: /var/log/mysql/error.log I don't find anything other than the errors I sent in the last comments.

kelunik commented 6 years ago

Are you using the CLI version of php?

sallsabil commented 6 years ago

yes

trowski commented 6 years ago

@sallsabil Please be sure assertions are enabled, as the debug code is wrapped with assert().

sallsabil commented 6 years ago

I avtivated assert() in php.ini file but no difference

sallsabil commented 6 years ago

Why can't you reproduce ?

sallsabil commented 6 years ago

How I understand my mysql doesn't support mysql_debug

kelunik commented 6 years ago

It's a constant you set in your client code (PHP), it has nothing to do with the server. You will see the log in the error log of your HTTP server, not the MySQL server.

sallsabil commented 6 years ago

https://dev.mysql.com/doc/refman/5.7/en/dbug-package.html : The MySQL server and most MySQL clients are compiled with the DBUG package originally created by Fred Fish. When you have configured MySQL for debugging, this package makes it possible to get a trace file of what the program is doing. See Section 28.5.1.2, “Creating Trace Files”.

you must have a mysqld that has been compiled with debugging support. You can check this by executing mysqld -V. If the version number ends with -debug, it is compiled with support for trace files.

My result of this command

mysqld -V

mysqld Ver 5.7.20-0ubuntu0.16.04.1 for Linux on x86_64 ((Ubuntu))

Not any -debug end.

kelunik commented 6 years ago

@sallsabil This client completely re-implements the MySQL protocol and doesn't make use of any other implementation for that.

Could you extract your code into a command line script that's easily runnable by others and provide a dump of your database table (with dummy data if applicable)?

kelunik commented 6 years ago

Thanks, but I guess we need more information to reproduce this behavior. Please provide either a Docker setup that reproduces the behavior or provide the debug log we requested. I'll close this issue as it hasn't been updated. We can always re-open the issue in case the requested information is provided.

valVk commented 6 years ago

@kelunik Than I'll try to help with this.

https://github.com/valVk/amph-mysql

Here is in table is 565529 rows

but in fact I can get only first 92 rows.