Support for both mysqli and PDO via my application

Of course it doesn’t - PDO can work with a range of SQL based databases and so does not support proprietary mySQL commands as they would break if you change the database.

Thanks everyone for the feedback. The main idea is to allow a wide variety of audience. This means both PDO and mysqli_* users can use this application. By only allowing PDO users to use this application, I am going against my goals which is to allow a wide variety of options for different kinds of users. I know PDO is the best choice, but it’s not whether it’s best for use, it’s whether it’s best for the audience. In the end, the audience will be the one who gets to decide because they are purchasing this application. Support just 1 library will question most users who aren’t familiar with that library if they are familiar with another.

I’m not going to neglect mysqli_* users because PDO is preferred. Although I will be forcing mysqli_* users to learn OOP because I am not going to allow them to use procedural at all since the default connection will be the OOP one.

The main concern at the moment is if this is the best approach. By supporting both PDO and mysqli_* compatibility, would this be safe at all?

Is your application procedural? Because if it isn’t, there is absolutely no reason to support mysqli. It will be just a waste of your effort for very little “audience expansion”.

Scott

You can mix and match your mysqli_ statements an OOP connection will still allow procedural calls.

It’s not intended to be used with procedural, but as @felgall said, you can use procedural with OOP I guess. The only thing I would see a problem is using procedural prepared statements with OOP connection. This could cause a fatal error.

Yes, but that is the extra effort you’d have, in order to make your application support both drivers. It makes no sense to me to do it, since you’re going to have to abstract away the procedural calls in your OOP APIs anyway. Your audience wins nothing really and in the end effect, you gain nothing.

Scott

I know you’re trying to help me Scott, but in the older version of my application, I already supported both mysqli_* or PDO. So basically the new idea is to allow the ease of switch between the two. I’m not going to throw away something that I already made to support mysqli_* in the older version. The support for either is already done with because I already made those models. The idea now is to allow the ease of transition from one library to another. Again, the audience will decide because they are purchasing it. There are rules and standards that the purchaser has to acknowledge and take as a responsibility when they purchase my application. So the library preference is based on them. Whether they like mysqli_* or PDO, they will have to choose.

If it’s just that before it came with one or the other, and you already have good working code for both, I see no reason why it couldn’t be one and the other as long as it doesn’t cause bloat or inefficiency.

It might take a bit to get the option support worked in, but I imagine that would be minimal compared to needing to code up a new feature from scratch. Well, as long as there wouldn’t be naming collisions, that could be hairy.

You don’t need this.

Hopefully you’re not wasting any ones time but your own but if you are you should stop now.

Supporting either mysqli_* or PDO is fine. Hell in this day and age only supporting PDO is fine. I mean what server doesn’t have PDO available…

Completely useless feature.

Thanks for the feedback. Yes, the only concern would be the naming collisions.

That’s a bit rude don’t you think? I’m wasting my own time. I find it that a lot of users in “this day and age” still use mysql_* and don’t want to switch over no matter what any one says to them. I’m just helping them out by putting my work for them so they don’t have to deal with trying to convert to something they don’t understand. But hey, I guess I’ll throw my work away if that’s what you are demanding me to do. I guess I’ll just have to be rude to people too. Being nice is too good to be true I guess. Now I wonder why there are so many rude developers in the PHP community. I wonder why everyone talks so much trash about PHP. It doesn’t seem like PHP is bad at all, but more so the community. But hey, if it floats your boat, I’ll throw away my work and make you happy. Good day sir.

Not at all. I’m a straight shooter. Besides, I didn’t say anything rude.

I would be very interested in your research which lead you to believe being able to simultaneously use mysqli_* and PDO is even a remotely necessary feature.

Use an abstraction layer like all the other modern frameworks. Create separate adaptors for PDO and MySQLi if you must and be done with it. Not mention if you use that pattern the system can be more easily expended to support other persistent storage mechanisms without breaking interfaces.

I agree. I just reread the OP and supporting both at the same time is total nonsense. I was misunderstanding the OP from the beginning and thinking the question was “Should I support mysqli or PDO”. It is an “either/ or” and not an “and” to offer the one or the other drive. If you have code already for both, then you can offer the option. mysqli OR PDO.

Scott

Total nonsense is too extreme - it may not be nonsense at all from a business point of view - even if he were to lose a very small minority of his customers by not supporting mysqli, this small minority might be important to him. Especially since supporting both drivers is not that much work - writing an abstraction class for both with a common interface is pretty simple and he can use one of the ready made DBAL options available and he is good to go right away.

The only thing I would advise for modern code is to go for the OO interface all along: use an abstraction class and use the db through the common db object. The db class can internally use either mysqli procedural or OO functions but the outer interface should be fully OO.

The OP said:

Why support mysqli_* or PDO? Why not support mysqli_* and PDO.

It is nonsense to support code that uses both drivers at the same time. It isn’t nonsense to support code that either uses mysqli or uses PDO. That was the point I was trying to make. That might not be what the OP meant. I am not sure.

Scott

This topic was automatically closed 91 days after the last reply. New replies are no longer allowed.