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

Problem with receiving all rows #64

Closed
sallsabil opened this issue Feb 7, 2018 · 20 comments
Closed

Problem with receiving all rows #64

sallsabil opened this issue Feb 7, 2018 · 20 comments

Comments

@sallsabil
Copy link

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
Copy link
Author

sallsabil commented Feb 8, 2018

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

@bwoebi
Copy link
Member

bwoebi commented Feb 8, 2018

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
Copy link
Author

sallsabil commented Feb 9, 2018

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
Copy link
Member

bwoebi commented Feb 9, 2018

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
Copy link
Author

sallsabil commented Feb 12, 2018

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
Copy link
Author

sallsabil commented Feb 12, 2018

I think the problem is from your project

@sallsabil
Copy link
Author

Am I right ?

@trowski
Copy link
Member

trowski commented Feb 13, 2018

@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
Copy link
Author

<?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
Copy link
Member

kelunik commented Feb 13, 2018

Are you using the CLI version of php?

@sallsabil
Copy link
Author

yes

@trowski
Copy link
Member

trowski commented Feb 14, 2018

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

@sallsabil
Copy link
Author

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

@sallsabil
Copy link
Author

Why can't you reproduce ?

@sallsabil
Copy link
Author

sallsabil commented Feb 20, 2018

How I understand my mysql doesn't support mysql_debug

@kelunik
Copy link
Member

kelunik commented Feb 20, 2018

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
Copy link
Author

sallsabil commented Feb 20, 2018

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
Copy link
Member

kelunik commented Feb 20, 2018

@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
Copy link
Member

kelunik commented May 13, 2018

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.

@kelunik kelunik closed this as completed May 13, 2018
@valVk
Copy link

valVk commented Jun 29, 2018

@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.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Development

No branches or pull requests

5 participants