-
-
Notifications
You must be signed in to change notification settings - Fork 1.1k
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
Unable to execute a query from a remote server such as Planetscale #1044
Comments
Error Shown
|
Are your What the output of Also remove |
We're running into the same issue on PlanetScale. The DB type is set to MySQL (hardcoded), and we don't use custom charsets, ports or ATTR cases. When we run debug() and ask Medoo to output the SQL it thinks it should run, the SQL statement outputted is correct and runs fine if we execute it manually, but for some reason, that SQL statement is not the one Medoo is actually running. We're able to replicate this with an extremely simple test case: global $container;
$container['db'] = function () {
return new Medoo(
[
'database_type' => 'mysql',
'database_name' => DB_NAME,
'server' => DB_HOST,
'username' => DB_USER,
'password' => DB_PASSWORD,
'option' => array(
\PDO::ATTR_ERRMODE => \PDO::ERRMODE_EXCEPTION,
\PDO::MYSQL_ATTR_SSL_CA => dirname(__FILE__) . '/cacert.pem'
)
]
);
};
$app = $container['db']->select( 'test_table',['id'], [ "LIMIT" => 1 ] ); where the test_table has 2 columns, an autoincrementing ID column and a VARCHAR value column We also get a syntax error like the previous reporter. We've confirmed the DB variables are correctly set (though we wouldn't get the syntax error but rather a connection failed error if they weren't) and we did the same for the cacert.pem to ensure it's in the right place (and again it would also trigger a different error if it was in the wrong place). Note, if it helps, PlanetScale offers a free db plan, and we're able to replicate this issue on that plan as well. |
Notably, if I run
The result works with no error. |
Ok, progress to report! I have figured out that with the following modifications, the library starts working on PlanetScale's databases: In the return '`' . $this->prefix . $table . '`'; and in the return strpos($column, '.') !== false ?
'`' . $this->prefix . str_replace('.', '"."', $column) . '`' :
'`' . $column . '`'; This has to be related to the handling of the MySQL ANSI_QUOTES |
Ok, so this seems to be done because of #578, where it discusses the use of double quotes instead of backticks to adhere to the SQL-92 standard. It seems that PlanetScale/Vitess might not support setting SQL_MODE = ANSI_QUOTES, which the library tries to do. Resultingly, the queries fail. |
It looks like Vitess doesn't support alternative SQL_MODES per doc here @catfan would it be okay if we submit a pr to allow for an option that would let PlanetScale users (and similar MySQL compatible database types that don't support the changing of SQL_MODE) to use backticks instead of double quotes for these two cases? Also, are there other places we need to account for the double quotes other than just the two places mentioned above if SQL_MODE can't be altered to ANSI_QUOTES? |
Note, the lack of ANSI_QUOTES support is a known issue for Vitess: vitessio/vitess#7769 which PlanetScale runs |
@chriscct7 Thank you for your inspection. I think it's good to call Vitess support ANSI_QUOTES to work like MySQL as possible. Medoo is using this standard quotation for all supported databases. For your case, you can just fork the Medoo project and change the quotation alone to make it work until Vitess support ANSI_QUOTES officially. |
I've put together the associated PR#1061 above in case it might be considered as a potential solution for this, considering that the likelihood of The usage is quite simple and after instantiating a new Medoo instance you would simply add a call to |
We've tested the PR orware submitted above and it works fantastically and solves #1044 when used. |
Is there any progress on this? Would love to see #1061 merged in. |
Information
Describe the Problem
Uncaught PDOException near either column name or FROM
Detail Code
The detail code you are using causes the problem.
Expected output
Working query with var_dump()
Notes
Working in native implementation
The text was updated successfully, but these errors were encountered: