Using mysqli with WordPress and future upgrades

All,
I’m trying to be good and get away from the mysql* php coding. I’m using wordpress for a new project and want to use the correct syntax for my database queries in my pages that I create. I want to use mysqli* but it looks like WordPress uses mysql* commands when connecting with the database. For example, they have some code like this in the wp-include/wp-db.php file:

if ( !@mysql_select_db( $db, $dbh ) ) {

I did read I can adjust this file wp-includes/load.php to use my own database code which is called before the wpdb variable is set.

Read More

I also want this to be scalable, so I can upgrade to future versions of WordPress. If I update these values and then need to upgrade WordPress, I think these values will get overwritten and my site has potential to not work correctly.

I tried to use the $wpdb value in creating a query on one my pages from within WordPress. I tried to do this following:

<?php
    global $wpdb;
    $info = $wpdb->get_results('Select * from vendor_types order by description ASC');
    foreach($info as $table) {
        echo $table->description;
    }
?>

When I do this, I get the correct output and it’s what I would expect it to be. However, is this the best way to do this from a WordPress perspective? I want to try and avoid using deprecated code in my applications?

Thanks!

Related posts

Leave a Reply