Forum Moderators: coopster

Message Too Old, No Replies

Converting to MySQLi

MySQL to MySQLi, steps to take

         

actolearn

3:36 pm on Apr 22, 2016 (gmt 0)

10+ Year Member



I use the following via my hosting company:
php extension: MySQL
phpMyAdmin 3.4.11.1
MySQL 5.5.34

If I understand correctly, I don't need to install anything. My above versions will support MySQLi.

Can I just use the same db table and just create a new product page with new MySQLi php code? Make sure it works and then convert my other website pages or do I need to practice on a copy of my db table?

I read somewhere that using the same DB table and php for both MySQL and MySQLi could cause things to crash but not sure that's correct.

robzilla

4:41 pm on Apr 22, 2016 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member Top Contributors Of The Month



Whether you can use MySQLi depends on your version of PHP more than your versions of MySQL or phpMyAdmin (but you probably can). Also, if your pages just read data from MySQL, there should be no problems, but if they're writing to the database and you make a mistake in your code (as I tend to do), you don't want some queries to fire when others do not, as that might introduce inconsistencies into your tables. If an inconsistency would be difficult to fix, e.g. due to the complexity of the tables or the amount of data written, I would probably use a separate set of tables, or even a separate database. And make a backup, of course.

Here's a tool you could use to guide you through the code changes: [github.com...]

actolearn

4:57 pm on Apr 22, 2016 (gmt 0)

10+ Year Member



My PHP version is 5.4.24

actolearn

5:18 pm on Apr 22, 2016 (gmt 0)

10+ Year Member



I'm wondering if I can just add new product pages using the new code and fix my old pages a little at a time. I would do this on a copy of my old table under a new table name.

Once I start correcting my old pages, I'd rather use search and replace with new code instead of trying github. That's a little scary looking for my small level of knowledge.

robzilla

8:16 pm on Apr 22, 2016 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member Top Contributors Of The Month



That's fine, of course, so long as you take into account all the small differences between the mysql and mysqli extensions (e.g. where the link identifier goes, that you now have to include the link identifier in functions like mysqli_real_escape_string and mysqli_error, etc). It's no problem using mysql on some pages and mysqli on others.

actolearn

8:36 pm on Apr 22, 2016 (gmt 0)

10+ Year Member



Thank you for your help. I've just finished creating a new database and new table to play around with before going live on my website. I'm sure I'll be back....

robzilla

9:19 pm on Apr 22, 2016 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member Top Contributors Of The Month



Good luck :-) Keep an eye on your error log (or temporarily enable error reporting).