Forum Moderators: coopster

Message Too Old, No Replies

Learning PHP

         

realestatesteve

2:40 pm on Dec 29, 2008 (gmt 0)

10+ Year Member



When I started learning PHP, I only learned how to use the old MySQL functions to connect and work with a database.

However, I've recently learned that MySQLi is the newer method of working with a database, and on top of that, the benefits of OOP.

My question is this: Is it worth it to take the time to learn MySQLi and OOP, or should is it not too important? I'm building a big application right now, and just a little worried that I'll have to go through all my code and update it all.

Thanks in advance!

Pico_Train

4:09 pm on Dec 29, 2008 (gmt 0)

10+ Year Member



Definetely look into OOP. It will make updating and understanding what's going on much easier in the future when the times comes to revisit things.

realestatesteve

4:22 pm on Dec 29, 2008 (gmt 0)

10+ Year Member



Yea, that's what I was thinking. I've experimented a bit with OOP, and can definitely see how it makes it it easier to work with the code.

There are some other things I want to implement as well, such as prepared statements.

I just wish I learned about all this BEFORE I started building my application! ><

coopster

5:01 pm on Dec 29, 2008 (gmt 0)

WebmasterWorld Administrator 10+ Year Member



Either way, prepared statements or not, you can sculpt a query that is safe to run. As far as mysql versus mysqli goes, if you are ready to make the move, make the move and start using your mysqli interfaces from here on out and address your *old* or existing applications when you have the time. Eventually I imagine the mysql API will be phased out and deprecated as that is where the direction is seemingly headed. Now, before anybody challenges that statement note that I stated EVENTUALLY here. I have been programming long enough to recognize development flow and patterns and I realize that folks don't develop a whole new set of APIs with the intention of maintaining the old API set forever.

As far as database access and queries go, consider an abstraction layer for future use. It doesn't necessarily have to be object oriented, it could be as simple as a bunch of functions stored in an included file. You include (or require_once) this file whenever you need to use your database. Now you have one place to worry about setting up and maintaining all your database processing routines. It will ease your maintenance and updates. The PEAR MDB2 (or DB) class was designed partly for this reason. Another reason was for cross-database compatibility. Trouble is, it may be more than you want for your own application.