3

I'm a php and mysql beginner, and I'm currently learning a section called "Accessing mysql database from web with php", in this book, the author only use the example of mysqli, but when I searched the google, I found pdo is somewhat better than mysqli, my question is: should I escape the mysqli one in the book and only learn pdo (from the web)?

3 Answers 3

5

Yes, absolutely go straight to PDO.

First, know that you should almost ALWAYS do parameterized queries when taking input from a client. PDO is SO much easier in that regard. (I say 'almost" because you can sometimes do things to 100% separate the client from the database via PHP)

Second, PDO is way more compact, so it needs far less lines of code.

Are there good tutorials on how to use PDO?

Bottom line: you have to learn it sooner or later. Why not sooner?

6
  • Thanks, I will go for pdo then, although I don't know what is parameterized queries yet :) Mar 11, 2013 at 4:16
  • @user1970939 don't we programmers love big words? it basically means "send the query first with placeholders for your data, put in the data immediately after in the assigned placeholders exactly as they are so not to destroy the database with sql injection" lol and sql injection just means putting a ; in the middle of your query to put in something fun like drop database;
    – user1382306
    Mar 11, 2013 at 4:20
  • I see, but sql injection seems to be a new word to me..anyway, thanks! Mar 11, 2013 at 4:47
  • @user1970939 np. it all sounds harder than it is. put the book down, and make stack your new best friend. g/l!
    – user1382306
    Mar 11, 2013 at 4:49
  • 1
    @YourCommonSense because you would've closed a newer one as a dupe lol
    – user1382306
    Mar 11, 2013 at 5:06
1

The problem with all mysqli examples - they cover only basic cases (and even with them being enormously wordy and bloated).
But when you trying to use mysqli in whatever real life application, it turns to be a real nightmare when dealing with prepared statements. Just try to bind an array of values into IN() operator and see.

So, to save yourself a ton of time and nerves, better go straight to PDO, it is reasonable and handy driver. You may start from PDO tag wiki here

0

You should follow the book first and then learn about prepared statements with PDO. There isn't really a right or wrong approach so there's no harm in learning both.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.