Thanks to visit codestin.com
Credit goes to github.com

Skip to content

[Lock] Don't allow mysqli to be used as it doesn't work #35375

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

Merged
merged 1 commit into from
Jan 27, 2020

Conversation

duncan3dc
Copy link
Contributor

Q A
Branch? 4.3
Bug fix? yes
New feature? no
Deprecations? no
Tickets
License MIT
Doc PR

Mysqli doesn't support named parameters, so if you pass a doctrine connection using mysqli then you get the following error:
You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near ':id, :token, UNIX_TIMESTAMP() + 300)'
This PR ensures a clear error is provided and suggests to use pdo_mysql instead

@nicolas-grekas
Copy link
Member

OR, we shouldn't use named parameters. Can you consider this option?

@duncan3dc
Copy link
Contributor Author

Yep that would be my preference. How would you like to approach regression tests?

@nicolas-grekas
Copy link
Member

How would you like to approach regression tests?

maybe just a comment inline telling why we don't use named params?

@duncan3dc
Copy link
Contributor Author

Seems like a dangerous approach to regression testing but as that's your preference I've pushed up a version that replaces named parameters with positional ones and removes the exception I previously added

@nicolas-grekas
Copy link
Member

I didn't say that's my preference :)
If you're up to adding a mysql server + mysqli client + functional test cases, that would be my preference. But I get that's a huge task for the change here...

@nicolas-grekas
Copy link
Member

Side question: why are you using mysqli instead of PDO?
We have more code in core that could benefit from similar changes, but is it worth it, vs telling ppl mysqli is not supported?

@duncan3dc
Copy link
Contributor Author

We had some legacy code in an application that was using mysqli, so instead of installing the pdo_mysql extension we just configured Doctrine to use mysqli too.

We're switching it to pdo_mysql now, I don't personally have a desire for mysqli support in locks. I'm happy to help out either way with this PR though and either set up a full mysqli test case or just add the exception to warn future devs about using mysqli with locks 🤷‍♂️

@nicolas-grekas
Copy link
Member

nicolas-grekas commented Jan 25, 2020

Thanks for the feedback. Since myslqi doesn't work already, let's throw an exception when someone tries to use it with Lock, but also with Cache or HttpFoundation's Session.

@duncan3dc
Copy link
Contributor Author

Ok I'll take a look at adding those exceptions now...

@duncan3dc
Copy link
Contributor Author

I've reverted this to the exception version now, and opened #35473 for cache, I couldn't see anywhere the session handler supports mysqli, but if you can point me towards it I'll gladly open a PR for that too

@nicolas-grekas
Copy link
Member

I'm thinking of ./src/Symfony/Component/HttpFoundation/Session/Storage/Handler/PdoSessionHandler.php

@duncan3dc
Copy link
Contributor Author

Sorry I wasn't clear, that's the file I've looked in, it only codes for mysql and mysql2, no mention of mysqli (in the 4.3 branch I'm working against)

@nicolas-grekas
Copy link
Member

OK, got it, you're right, nothing to change there.

nicolas-grekas added a commit that referenced this pull request Jan 27, 2020
… (duncan3dc)

This PR was merged into the 4.3 branch.

Discussion
----------

[Cache] Don't allow mysqli to be used as it doesn't work

| Q             | A
| ------------- | ---
| Branch?       | 4.3
| Bug fix?      | yes
| New feature?  | no
| Deprecations? | no
| Tickets       |
| License       | MIT
| Doc PR        |

As discussed in #35375 Mysqli doesn't support named parameters, so if you pass a doctrine connection using `mysqli` then you get errors for any queries using named parameters.
This PR ensures a clear error is provided and suggests to use `pdo_mysql` instead

Commits
-------

a786448 Mysqli doesn't support the named parameters used by PdoAdapter
@nicolas-grekas
Copy link
Member

Thank you @duncan3dc.

nicolas-grekas added a commit that referenced this pull request Jan 27, 2020
…(duncan3dc)

This PR was merged into the 4.3 branch.

Discussion
----------

[Lock] Don't allow mysqli to be used as it doesn't work

| Q             | A
| ------------- | ---
| Branch?       | 4.3
| Bug fix?      | yes
| New feature?  | no
| Deprecations? | no
| Tickets       |
| License       | MIT
| Doc PR        |

Mysqli doesn't support named parameters, so if you pass a doctrine connection using `mysqli` then you get the following error:
`You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near ':id, :token, UNIX_TIMESTAMP() + 300)'`
This PR ensures a clear error is provided and suggests to use `pdo_mysql` instead

Commits
-------

ef3bcda Mysqli doesn't support the named parameters used by PdoStore
@nicolas-grekas nicolas-grekas merged commit ef3bcda into symfony:4.3 Jan 27, 2020
@duncan3dc duncan3dc deleted the mysqli-locks branch January 27, 2020 10:31
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants