-
Notifications
You must be signed in to change notification settings - Fork 32
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
Request for vote - ONLY support PDO database driver #198
Comments
My short comment on this:
I am against dropping DB prefix. But besides that - my only concern is about amount of time for rewriting the code and changing habit for SQL queries. I saw, that You have done it already. It still needs to be review for Copona, because we have been based on older Opencart, and it's hard to find the time for this right now. I have told it already - the best framework for anyone is the one, you know. If someone does not know PDO, this will be drawback for choosing Copona. |
1 - The question was strictly about dropping the following drivers from /system/library/db/ 2 - There is literally NO change required to switch to the PDO driver today. You just change DB_DRIVER from The only changing that happens is if you actually want to use prepared statements. But switching to the PDO driver means you CAN use prepared statements in a simple manner (rather than tediously having to bind each parameter, etc, PDO lets you put your parameters as an array within Yes, things would have to be reviewed before copying and pasting, mainly because you're based off of OC 2.3, and I forked from 3.0. Point is, switching copona from using 1 - Delete the 3 files from Library/db/ directory 2 - Change install routine to not allow selecting database driver. 3 - In existing installs, change DB_DRIVER constant from Really, that's all you need to do. Prepare statements are the next step, but you don't have to do that to switch drivers |
Secondly as for DB_PREFIX goes, if you insist on keeping it for those cases, I would still suggest stripping it from the existing SQL (simple find and replace), and replace with Thereafter, if you need a different table prefix for a site, you can build a function in the You still get to have prefixes, and your database code becomes a little readable at least. Anything to improve readability of OC SQL is good. But wading through event the simplest query like: Just offering a suggestion. We have slightly different ideas/goals, but really, I'm just trying to make all of our lives at least a little easier (as are you, @prhost and everyone else :) The best part about OC, I think, is the database that's been built. It's extensive, and would take a long time to recreate. But the decisions that have been made long before us about how to implement the SQL and PHP makes the code extremely difficult to edit/manipulate or anything else... |
Prepare statements would be an improvement. It's so easy to make a mistake with the escaping and casting in the SQL, that I see a extensions with them missing all the time. However I can't see the point of removing the other drivers until are repare statements actually used and make the incompatible or flawed. |
@ADDCreative - if you look at the rewrites I've done over on http://github.com/lucasjkr/opencommerce (look in common/model as I'm merging models together), many of the models have already been rewritten to use prepared statements. If Copona switched to PDO only, I could bring over most of them (I started from OC 3.0 vs Copona which is based on OC 2.3). But that will only work with the mpdo driver. Again, I'm using named placeholders instead of positional placeholders, because it's easier to troubleshoot (placeholders can appear in the array in any order). Other databases can be supported, but again, it's dependent on dialect. I know that OC's SQL installer wouldn't even create the first table in MSSQL. Unless one of us is going to run Postgres, MSSQL, etc, it seems pointless to say they're supported. |
Topic to vote on: Drop support for all database access methods except PDO.
Background: opencart has abstracted its database access methods, so that it can use a variety of native PHP drivers including: mysql, mysqli, mssql, Postgres, and PDO.
A long time ago, I convinced @arnis to drop support for old style mysql_ drivers, given that they were deprecated in later versions of PHP5 and removed from php7
We've had debates about what version of MySQL to support, but we've not addressed all of the other "supported" databases. I use quotes because while there are database wrappers for a variety of databases, I doubt that most of opencart would install or even execute using those drivers due to MySQL specific code.
I am therefor suggesting dropping any pretend support for anything but MySQL, and not only that, drop support for the mysqli driver and ONLY use PDO.
Benefits are:
PDO is database agnostic. The same code should work across any database that has PDO drivers available. The SQL itself would need to be tweaked, though, so it would pose the same difficulty to support other databases using PDO as it would as it is currently.
PDO also supports positional placeholders in prepared statements. In case you're not aware, prepared statements are a means of inserting data into the directly into database, without all the arduous casting and escaping that litters the queries in Opencart.
For reference, look at the insert queries in Copona/opencart compared to what I've done in my own little project (working name: Opencommerce -also a fork, but being very focused/dropping support for lots of things in order to clean up the code base) - I’ll continue on that, but I wish I could share stuff over to you guys.. Note: I also got rid of DB_PREFIX, but even discounting that:
https://raw.githubusercontent.com/copona/copona/master/admin/model/catalog/product.php
vs
https://raw.githubusercontent.com/lucasjkr/opencommerce/master/common/model/catalog/product_admin.php
Named placeholders read easier, and are not positionally dependent - big plus once you have more than two parameters going into queries.
Importantly, @prhost is working on implementing an ORM in Copona 99% likely this will require PDO as well, and for a while there will likely be raw queries AND ORM generated queries being generated. They should all be sent through the same adapter.
Personally, I don’t see ANY downside to making Copona only support the
mpdo
driver and dropping support formysqli
, along with all the non-MySQL databases. IF you want to support other databases in the future, you can through PDO. And will require the same amount of effort as it would currently (rewriting SQL), unless and until @prhost finishes his ORM task.So, hopefully @arnisjuraga will allow this to be voted on.
The text was updated successfully, but these errors were encountered: