Should they ever be used together? I've been told that you shouldn't use MySQLi with OOP, and PDO is similar so I'm not sure whether I should use these together or not? In which circumstance should I use PDO and which shouldd I use OOP?
Printable View
Should they ever be used together? I've been told that you shouldn't use MySQLi with OOP, and PDO is similar so I'm not sure whether I should use these together or not? In which circumstance should I use PDO and which shouldd I use OOP?
You should use OOP with both extensions, MySQLi and for PDO.
You don't have to with MySQLi, but you certainly can. You're even forced to use OOP if you choose to use the PDO extension, and I recommend the OOP capabilities with MySQLi, too.
Ok wait let me explain this a little better:
Object Oriented Programming is a style of programming. PDO, MySQLi; are extensions for PHP. PHP supports OOP (a style of programming). The PDO extension requires you to use OOP. The MySQL extension is used (and styled) as a Procedural or Structured kind of Programming.
The MySQLi extension is the MySQL improved extension, with that said, it still supports Structured and Procedural Programming styles. In PHP5 The language's OOP techniques greatly improved. Therefore the new MySQLi extension also supports OOP structure- like PDO.
You can use all of the PHP extensions with your PHP application whether your application is coded procedurally, structurally, or Object Oriented- you can integrate any PHP extension with your application.
The way you use the extension depends on how it's coded. For example, you're forced to use OOP techniques (such as instantiation) when using the PDO extension, but you can instantiate the objects and use the PDO methods and such right inside your Procedural code.
Things you need to learn include operators like "->", "::", keywords like "new" and how objects interact with methods, constants, etc. You cannot comfortably use PDO without knowing these language features.
Eventually, advice that makes sense and is correct! Many thanks for explaining this to me, I've learnt so much in a few months from moving away from looking at advice from friends and taking it from others who are more knowledgeable. Time to get working on a more stable, secure and user-friendly project! Haha :)