Unfortunately, I wrote a lot of code using mysql_query, mysql_fetch_array and mysql_num_rows calls. It’s close to finish, but today I’ve read about PDO, mysqli.
The only hope I shouldn’t start over and spend weeks is the answer of
Well if you already have a lot of code written, I wouldn’t bother, but for any new projects I would strictly suggest PDO.– musicfreak May 15 ’09 at 5:23
The answer was 2.5 years ago, so the answer could be out of date as well.
One of the reasons to switch to PDO is that it helps protect against SQL injections. I “clean” all inputed strings so I think that’s not an argument for me. Better performance (if it’s really better) is important as well, but the web-site works fine even now.
Should I spend weeks to rewrite the code? Or that’s not a big deal if it works?
Sorry for this question, but I’m confused. Reading more documentation doesn’t help me to choose a proper answer in my case. I’m not sure if I spend a lot of time I will get any better results or performance (alghout if I start it now, I would start with PDO as it is newer).
Thank you.
You don’t have to worry about switching. If the project is almost ready, and you will start on a new one soon, just follow the new, better practices with your next project.
On the other hand, you just collected some useful experience. With a well-designed codebase, it should not be a lot of worry to switch between mysql_* and PDO. Write objects and methods to gather data, so your actual SQL calls will be quite few.