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

Unrecognized keyword. (near "CHARACTER SET" at position 4) #12279

Closed
0x1ad1b88 opened this Issue May 29, 2016 · 30 comments

Comments

Projects
None yet
6 participants
@0x1ad1b88

0x1ad1b88 commented May 29, 2016

Steps to reproduce

  1. checkout tags/RELEASE_4_6_2
  2. try to login to a mysql server

Expected behaviour

I would expect to get an ui shown...

Actual behaviour

Displays an error
`Error

Static analysis:

2 errors were found during analysis.

Unrecognized keyword. (near "CHARACTER SET" at position 4)
Unexpected token. (near "'utf8'" at position 18)
SQL query: Edit Edit

SET CHARACTER SET 'utf8';`

Server configuration

Operating system:
Debian 8.4

Web server:
Apache 2.4.10-10+deb8u4
Database:
several, including mariadb 10.1.14+maria-1~jessie
PHP version:
5.6.20+dfsg-0+deb8u1
phpMyAdmin version:
RELEASE_4_6_2 / master

Client configuration

Browser:
several, appeared on all, including latest versions of chromium and firefox
Operating system:
several, appeared on all, including ubuntu 15.10, ubuntu 16.04, debian wheezy, debian jessie, debian testing, windows 10, arch linux rolling

I should mention, that tags/RELEASE_4_6_0 worked fine... and reverting to it still does the job.

@nijel nijel added the question label May 30, 2016

@nijel

This comment has been minimized.

Member

nijel commented May 30, 2016

I don't recall any change which could be relevant here and also it works fine in all setups I've seen.

Anyway this should not be the only error you get, is there something else reported?

@0x1ad1b88

This comment has been minimized.

0x1ad1b88 commented May 30, 2016

nope,

if i checkout tags/RELEASE_4_6_2 and comment out the set statement it complains about the next one...

Error

SQL query: Edit Edit

SET lc_messages = 'en_US';

nvm... if going back in browser history i get the followign errors: around the login form

mysqli_real_connect() expects parameter 6 to be long, string given
--
Warning in ./libraries/dbi/DBIMysqli.php#257
mysqli_query(): invalid object or resource mysqli

Backtrace

./libraries/dbi/DBIMysqli.php#257: mysqli_query(
object,
string 'SET CHARACTER SET \'utf8\';',
integer 0,
)
./libraries/DatabaseInterface.php#260: PMA\libraries\dbi\DBIMysqli->realQuery(
string 'SET CHARACTER SET \'utf8\';',
object,
integer 1,
)
./libraries/DatabaseInterface.php#89: PMA\libraries\DatabaseInterface->tryQuery(
string 'string \'SET CHARACTER SET \\\'utf8\\\';\'',
object,
string 'integer 1',
string 'boolean true',
)
./libraries/DatabaseInterface.php#1529: PMA\libraries\DatabaseInterface->query(
string 'string \'string \\\'string \\\\\\\'SET CHARACTER SET \\\\\\\\\\\\\\\'utf8\\\\\\\\\\\\\\\';\\\\\\\'\\\'\'',
object,
string 'string \'string \\\'integer 1\\\'\'',
)
./libraries/DatabaseInterface.php#2392: PMA\libraries\DatabaseInterface->postConnect(object)
./libraries/common.inc.php#848: PMA\libraries\DatabaseInterface->connect(
string ********,
string ********,
string ********,
)
./index.php#13: require_once(./libraries/common.inc.php)
--

Warning in ./libraries/dbi/DBIMysqli.php#461
mysqli_affected_rows(): invalid object or resource mysqli

Backtrace

./libraries/dbi/DBIMysqli.php#461: mysqli_affected_rows(object)
./libraries/DatabaseInterface.php#2656: PMA\libraries\dbi\DBIMysqli->affectedRows(object)
./libraries/DatabaseInterface.php#263: PMA\libraries\DatabaseInterface->affectedRows(
object,
boolean false,
)
./libraries/DatabaseInterface.php#89: PMA\libraries\DatabaseInterface->tryQuery(
string 'string \'SET CHARACTER SET \\\'utf8\\\';\'',
object,
string 'integer 1',
string 'boolean true',
)
./libraries/DatabaseInterface.php#1529: PMA\libraries\DatabaseInterface->query(
string 'string \'string \\\'string \\\\\\\'SET CHARACTER SET \\\\\\\\\\\\\\\'utf8\\\\\\\\\\\\\\\';\\\\\\\'\\\'\'',
object,
string 'string \'string \\\'integer 1\\\'\'',
)
./libraries/DatabaseInterface.php#2392: PMA\libraries\DatabaseInterface->postConnect(object)
./libraries/common.inc.php#848: PMA\libraries\DatabaseInterface->connect(
string ********,
string ********,
string ********,
)
./index.php#13: require_once(./libraries/common.inc.php)


-- 


Warning in ./libraries/dbi/DBIMysqli.php#418
mysqli_errno(): invalid object or resource mysqli

Backtrace

./libraries/dbi/DBIMysqli.php#418: mysqli_errno(object)
./libraries/DatabaseInterface.php#2598: PMA\libraries\dbi\DBIMysqli->getError(object)
./libraries/DatabaseInterface.php#90: PMA\libraries\DatabaseInterface->getError(object)
./libraries/DatabaseInterface.php#1529: PMA\libraries\DatabaseInterface->query(
string 'string \'string \\\'string \\\\\\\'SET CHARACTER SET \\\\\\\\\\\\\\\'utf8\\\\\\\\\\\\\\\';\\\\\\\'\\\'\'',
object,
string 'string \'string \\\'integer 1\\\'\'',
)
./libraries/DatabaseInterface.php#2392: PMA\libraries\DatabaseInterface->postConnect(object)
./libraries/common.inc.php#848: PMA\libraries\DatabaseInterface->connect(
string ********,
string ********,
string ********,
)
./index.php#13: require_once(./libraries/common.inc.php)

--

Warning in ./libraries/dbi/DBIMysqli.php#419
mysqli_error(): invalid object or resource mysqli

Backtrace

./libraries/dbi/DBIMysqli.php#419: mysqli_error(object)
./libraries/DatabaseInterface.php#2598: PMA\libraries\dbi\DBIMysqli->getError(object)
./libraries/DatabaseInterface.php#90: PMA\libraries\DatabaseInterface->getError(object)
./libraries/DatabaseInterface.php#1529: PMA\libraries\DatabaseInterface->query(
string 'string \'string \\\'string \\\\\\\'SET CHARACTER SET \\\\\\\\\\\\\\\'utf8\\\\\\\\\\\\\\\';\\\\\\\'\\\'\'',
object,
string 'string \'string \\\'integer 1\\\'\'',
)
./libraries/DatabaseInterface.php#2392: PMA\libraries\DatabaseInterface->postConnect(object)
./libraries/common.inc.php#848: PMA\libraries\DatabaseInterface->connect(
string ********,
string ********,
string ********,
)
./index.php#13: require_once(./libraries/common.inc.php)
@marcowarga

This comment has been minimized.

marcowarga commented Jun 1, 2016

Had the same errors with these related packages installed on wheezy:

ii  libdbd-mysql-perl                               4.021-1+b1                    amd64
ii  libmysqlclient18:amd64                          5.6.29-1~dotdeb+7.1           amd64
ii  mysql-client                                    5.6.29-1~dotdeb+7.1           all  
ii  mysql-client-5.6                                5.6.29-1~dotdeb+7.1           amd64
ii  mysql-client-core-5.6                           5.6.29-1~dotdeb+7.1           amd64
ii  mysql-common                                    5.6.29-1~dotdeb+7.1           all  
ii  mysql-common-5.6                                5.6.29-1~dotdeb+7.1           all  
ii  mysql-server                                    5.6.29-1~dotdeb+7.1           all  
ii  mysql-server-5.6                                5.6.29-1~dotdeb+7.1           amd64
ii  mysql-server-core-5.6                           5.6.29-1~dotdeb+7.1           amd64
ii  mysql-source-5.6                                5.6.29-1~dotdeb+7.1           amd64
ii  mysql-testsuite-5.6                             5.6.29-1~dotdeb+7.1           amd64
ii  php5-mysql                                      5.6.22-1~dotdeb+7.1           amd64

I was able to fix it by removing php5-mysql and installing php5-mysqlnd.

@hexathos

This comment has been minimized.

Contributor

hexathos commented Jun 3, 2016

Same problem here

root@hx-web-intern:~# dpkg -l | grep php
ii  php-pear                       5.6.20+dfsg-0+deb8u1                 all          PEAR - PHP Extension and Application Repository
ii  php5-cli                       5.6.20+dfsg-0+deb8u1                 amd64        command-line interpreter for the php5 scripting language
ii  php5-common                    5.6.20+dfsg-0+deb8u1                 amd64        Common files for packages built from the php5 source
ii  php5-curl                      5.6.20+dfsg-0+deb8u1                 amd64        CURL module for php5
ii  php5-fpm                       5.6.20+dfsg-0+deb8u1                 amd64        server-side, HTML-embedded scripting language (FPM-CGI binary)
ii  php5-gd                        5.6.20+dfsg-0+deb8u1                 amd64        GD module for php5
ii  php5-geoip                     1.1.0-2                              amd64        GeoIP module for php5
ii  php5-gmp                       5.6.20+dfsg-0+deb8u1                 amd64        GMP module for php5
ii  php5-gnupg                     1.3.3-1+b1                           amd64        wrapper around the gpgme library
ii  php5-imagick                   3.2.0~rc1-1                          amd64        Provides a wrapper to the ImageMagick library
ii  php5-intl                      5.6.20+dfsg-0+deb8u1                 amd64        internationalisation module for php5
ii  php5-json                      1.3.6-1                              amd64        JSON module for php5
ii  php5-ldap                      5.6.20+dfsg-0+deb8u1                 amd64        LDAP module for php5
ii  php5-mcrypt                    5.6.20+dfsg-0+deb8u1                 amd64        MCrypt module for php5
ii  php5-mongo                     1.5.7-1                              amd64        MongoDB database driver
ii  php5-mysql                     5.6.20+dfsg-0+deb8u1                 amd64        MySQL module for php5
ii  php5-readline                  5.6.20+dfsg-0+deb8u1                 amd64        Readline module for php5
ii  php5-rrd                       1.1.3-1+b1                           amd64        PHP bindings to rrd tool system
ii  php5-ssh2                      0.12-3                               amd64        Bindings for the libssh2 library
ii  php5-stomp                     1.0.5-1+b1                           amd64        Streaming Text Oriented Messaging Protocol (STOMP) client module for PHP 5
root@hx-web-intern:~# dpkg -l | grep mysql
ii  libdbd-mysql-perl              4.028-2+b1                           amd64        Perl5 database interface to the MySQL database
ii  libmysqlclient18               10.1.14+maria-1~jessie               amd64        Virtual package to satisfy external depends
ii  mariadb-common                 10.1.14+maria-1~jessie               all          MariaDB database common files (e.g. /etc/mysql/conf.d/mariadb.cnf)
ii  mysql-common                   10.1.14+maria-1~jessie               all          MariaDB database common files (e.g. /etc/mysql/my.cnf)
ii  php5-mysql                     5.6.20+dfsg-0+deb8u1                 amd64        MySQL module for php5

root@hx-mariadb:~# dpkg -l | grep mysql
ii  libdbd-mysql-perl              4.028-2+b1                           amd64        Perl5 database interface to the MySQL database
ii  libmysqlclient18               10.1.14+maria-1~jessie               amd64        Virtual package to satisfy external depends
ii  mariadb-common                 10.1.14+maria-1~jessie               all          MariaDB database common files (e.g. /etc/mysql/conf.d/mariadb.cnf)
ii  mysql-common                   10.1.14+maria-1~jessie               all          MariaDB database common files (e.g. /etc/mysql/my.cnf)
root@hx-mariadb:~# dpkg -l | grep maria
ii  libmariadbclient18             10.1.14+maria-1~jessie               amd64        MariaDB database client library
ii  libmysqlclient18               10.1.14+maria-1~jessie               amd64        Virtual package to satisfy external depends
ii  mariadb-client                 10.1.14+maria-1~jessie               all          MariaDB database client (metapackage depending on the latest version)
ii  mariadb-client-10.1            10.1.14+maria-1~jessie               amd64        MariaDB database client binaries
ii  mariadb-client-core-10.1       10.1.14+maria-1~jessie               amd64        MariaDB database core client binaries
ii  mariadb-common                 10.1.14+maria-1~jessie               all          MariaDB database common files (e.g. /etc/mysql/conf.d/mariadb.cnf)
ii  mariadb-server                 10.1.14+maria-1~jessie               all          MariaDB database server (metapackage depending on the latest version)
ii  mariadb-server-10.1            10.1.14+maria-1~jessie               amd64        MariaDB database server binaries
ii  mariadb-server-core-10.1       10.1.14+maria-1~jessie               amd64        MariaDB database core server files
ii  mysql-common                   10.1.14+maria-1~jessie               all          MariaDB database common files (e.g. /etc/mysql/my.cnf)

@nijel nijel self-assigned this Jun 3, 2016

@nijel nijel added bug and removed question labels Jun 3, 2016

@nijel nijel added this to the 4.6.3 milestone Jun 3, 2016

nijel added a commit that referenced this issue Jun 3, 2016

Fixed error reporting on connect problems
The mysqli_real_connect seems to return NULL on invalid parameters, so
we need to handle it as well. This doesn't seem to be documented
anywhere.

Issue #12279

Signed-off-by: Michal Čihař <michal@cihar.com>
@nijel

This comment has been minimized.

Member

nijel commented Jun 3, 2016

I've fixed one error (phpMyAdmin not properly detecting failure on connect due to mysqli_real_connect returning not documented null instead of false).

However there is still one bug to be solved - why do you get the string as port. The code really seems to pass integer in all cases there. What is your configuration?

@hexathos

This comment has been minimized.

Contributor

hexathos commented Jun 3, 2016

If it helps i could offer you php fpm configuration, apache conf and even access to the machine phpmyadmin runs on (open vpn)

@nijel

This comment has been minimized.

Member

nijel commented Jun 3, 2016

The config.inc.php should be enough

@hexathos

This comment has been minimized.

Contributor

hexathos commented Jun 3, 2016

tested also with disabled compression

phpmyadmin@hx-web-intern:~/html$ grep -v blowfish config.inc.php 
<?php
$i = 0;

$i++;
$cfg['Servers'][$i]['auth_type'] = 'cookie';
$cfg['Servers'][$i]['verbose'] = 'Hexathos - MariaDB 10';
$cfg['Servers'][$i]['host'] = 'mysql';
$cfg['Servers'][$i]['connect_type'] = 'tcp';
$cfg['Servers'][$i]['compress'] = true;
$cfg['Servers'][$i]['AllowNoPassword'] = false;
$cfg['PmaAbsoluteUri'] = 'https://phpmyadmin.hexathos.de/';

$i++;
$cfg['Servers'][$i]['auth_type'] = 'cookie';
$cfg['Servers'][$i]['host'] = '10.69.0.7';
$cfg['Servers'][$i]['verbose'] = 'MySQL';
$cfg['Servers'][$i]['connect_type'] = 'tcp';
$cfg['Servers'][$i]['compress'] = true;
$cfg['Servers'][$i]['AllowNoPassword'] = false;

$cfg['UploadDir'] = '';
$cfg['SaveDir'] = '';


@nijel

This comment has been minimized.

Member

nijel commented Jun 3, 2016

@hexathos What phpMyAdmin version do you use? Is it 4.6.2 as well?

@hexathos

This comment has been minimized.

Contributor

hexathos commented Jun 3, 2016

The error occurs in 4.6.2 ... 4.6.0 works fine

nijel added a commit that referenced this issue Jun 3, 2016

Simplify server port handling
The intval function does return 0 for empty string, so we really do not
have to special case here.

Issue #12279

Signed-off-by: Michal Čihař <michal@cihar.com>
@nijel

This comment has been minimized.

Member

nijel commented Jun 3, 2016

Can you try it with current QA_4_6 (or master) branch? I've made some cleanups to related code, but I'm really not sure if it can improve something.

@hexathos

This comment has been minimized.

Contributor

hexathos commented Jun 3, 2016

Doesnt't work (master with updated composer depencies)

#0 Cannot log in to the MySQL server

That shouldn't cause the troubles...
mysqli_real_connect(): Headers and client library minor version mismatch. Headers:50547 Library:100114

But that maybe
mysqli_real_connect() expects parameter 6 to be long, string given

@hexathos

This comment has been minimized.

Contributor

hexathos commented Jun 3, 2016

I vardumped the server port, and it says int(3306) ... so now i am confused

@nijel

This comment has been minimized.

Member

nijel commented Jun 3, 2016

I really couldn't find code path which would make it be string, so at least this behaves as expected. Can you try whether it works in really simple PHP script?


<?php

$link = mysqli_init();
if (!$link) {
    die('mysqli_init failed');
}

if (!mysqli_real_connect($link, 'mysql', 'my_user', 'my_password', 'my_db', 3306)) {
    die('Connect Error (' . mysqli_connect_errno() . ') '
            . mysqli_connect_error());
}

echo 'Success... ' . mysqli_get_host_info($link) . "\n";

mysqli_close($link);
?>
@hexathos

This comment has been minimized.

Contributor

hexathos commented Jun 3, 2016

PHP Warning: mysqli_real_connect(): Headers and client library minor version mismatch. Headers:50547 Library:100114 in /home/phpmyadmin/phpmyadmin/t.php on line 8
Success... mysql via TCP/IP

But to be honest, it even works if i pass the port param as string in ' or "

@nijel

This comment has been minimized.

Member

nijel commented Jun 3, 2016

Hmm, maybe it's complaining about different parameter then? This is really getting confusing...

@hexathos

This comment has been minimized.

Contributor

hexathos commented Jun 3, 2016

Hmm it works if a error_reporting(0); is palced before the mysqli_real_connect call... -.-

Switching to php5-mysqlnd doesn't fix the parameter error, sadly, just the originally reported set query ;/

@ghost

This comment has been minimized.

ghost commented Jun 3, 2016

Having the same problem as OP...

@joonaskaskisola

This comment has been minimized.

joonaskaskisola commented Jun 5, 2016

Same here, 4.6.0 seems to be working correctly.

@nijel

This comment has been minimized.

Member

nijel commented Jun 6, 2016

The only intended change between 4.6.0 and 4.6.1 is to display errors shown when connecting. This really should not cause this, but you can try adding @ in front of mysqli_real_connect call to see if it helps...

@hexathos

This comment has been minimized.

Contributor

hexathos commented Jun 6, 2016

works with @ operator too.

@nijel

This comment has been minimized.

Member

nijel commented Jun 6, 2016

Just to be sure, can you please try that the test script with error reporting fails?

<?php
error_reporting(E_ALL);
$link = mysqli_init();
if (!$link) {
    die('mysqli_init failed');
}

if (!mysqli_real_connect($link, 'mysql', 'my_user', 'my_password', 'my_db', 3306)) {
    die('Connect Error (' . mysqli_connect_errno() . ') '
            . mysqli_connect_error());
}

echo 'Success... ' . mysqli_get_host_info($link) . "\n";

mysqli_close($link);
?>

PS: Sorry to bother you so much, but I was unable to reproduce it so far...

@hexathos

This comment has been minimized.

Contributor

hexathos commented Jun 6, 2016

Well... it does not fail... not via apache->fpm and not via cli... -.- not on php5-mysql and not on php5-mysqlnd

i don't understand it ;c(

@nijel

This comment has been minimized.

Member

nijel commented Jun 6, 2016

One more idea: it might be related to error handler we install. Can you try to change it to disable further processing of handled errors?

--- a/libraries/ErrorHandler.php
+++ b/libraries/ErrorHandler.php
@@ -137,6 +137,9 @@ class ErrorHandler
             return;
         }
         $this->addError($errstr, $errno, $errfile, $errline, true);
+
+        /* Don't execute PHP internal error handler */
+        return true;
     }

     /**
@hexathos

This comment has been minimized.

Contributor

hexathos commented Jun 6, 2016

I figured out, that client_flags is (int)0, not null, and modified the mysqli_real_connect example to use the client flags attribute it looks like the first if block is not used in my case. but it changed nothing ...

adding the return true; didn't change the behavior phpmyadmin tells #0 Cannot log in to the MySQL server

commenting out $this->addError($errstr, $errno, $errfile, $errline, true); and removing the added return true fixed the issue for me.

@hexathos

This comment has been minimized.

Contributor

hexathos commented Jun 6, 2016

I wrote errornumbers to a file and it results the following...

diff --git a/libraries/ErrorHandler.php b/libraries/ErrorHandler.php
index 8bd408d..f48e964 100644
--- a/libraries/ErrorHandler.php
+++ b/libraries/ErrorHandler.php
@@ -137,6 +137,7 @@ class ErrorHandler
             return;
         }
         $this->addError($errstr, $errno, $errfile, $errline, true);
+       //return true;
     }

     /**
@@ -173,8 +174,8 @@ class ErrorHandler

         // do not repeat errors
         $this->errors[$error->getHash()] = $error;
-
-        switch ($error->getNumber()) {
+         file_put_contents ( "/home/phpmyadmin/errors.log", $error->getNumber() ." ".$errno." ".$errstr.PHP_EOL,  FILE_APPEND );
+       switch ($error->getNumber()) {
         case E_USER_NOTICE:
         case E_USER_WARNING:
         case E_STRICT:

2 2 mysqli_real_connect(): Headers and client library minor version mismatch. Headers:50547 Library:100114
2 2 mysqli_real_connect() expects parameter 6 to be long, string given
256 256 mysqli_real_connect(): Headers and client library minor version mismatch. Headers:50547 Library:100114
256 256 mysqli_real_connect() expects parameter 6 to be long, string given

with added file and line:

256 256 on /home/phpmyadmin/phpmyadmin/libraries/DatabaseInterface.php:2255 mysqli_real_connect(): Headers and client library minor version mismatch. Headers:50547 Library:100114
256 256 on /home/phpmyadmin/phpmyadmin/libraries/DatabaseInterface.php:2255 mysqli_real_connect() expects parameter 6 to be long, string given

first error

/home/phpmyadmin/phpmyadmin/libraries/dbi/DBIMysqli.php:106 

I hope it helps ;-)

@nijel

This comment has been minimized.

Member

nijel commented Jun 6, 2016

This is what I'd expect (first two are coming from PHP, second ones when processing then inside phpMyAdmin).

The problem is mysqli_real_connect() expects parameter 6 to be long, string given and I really fail to see how our custom error handling could cause to trigger it, but it obviously does do that.

@nijel nijel closed this in 4fd2709 Jun 6, 2016

@nijel

This comment has been minimized.

Member

nijel commented Jun 6, 2016

I've finally set up test environment and found out what the problem is - PHP is passing stack frame as reference to the error handling code and it does process it for display, converting all values to displayable strings. When writing this code I didn't realize that changing error stack frame will change the actual stack frame as well.

@hexathos

This comment has been minimized.

Contributor

hexathos commented Jun 6, 2016

QA_4_6 works for me now, thanks ;)

@MadaSociety

This comment has been minimized.

MadaSociety commented Jun 16, 2016

Hi, I confirm, installing php5-mysqlnd fix the problem. Thank you @marcowarga
👍

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