Migrating MYSQL to $wpdb
-
So a few years ago I used wordpress to create our website but 90% of the displayed content is actually created through a database. The lay out is created with custom shortcodes that I wrote in PHP. Basically the PHP scripts get information out of the database with MySQL and formats it in WP shortcodes before printing it to the page.
Recently the entire database driven part of the website stopped working. I tried fixing it; I read that MySQL_query and similar commands should no longer be used so I figured I should try to do the right thing and rewrite the scripts to use the $wpdb variable but honestly, I have no idea where to begin and my changes do not seem to work or result in endless loops. I tried simply replacing any MySQL_ command with mysqli_ commands but that did not fix the problem. The database I use is part of the WP database, so I shouldn’t have to set up a connection (I never have in the past) so it might just be that I am at a loss in regards to syntax.
For example:
$result = mysqli_query("SELECT * FROM es_games WHERE platform_ID=($id) HAVING game_dev = 0 ORDER BY game_title ");
I think should be:
$result = $wpdb->get_results("SELECT * FROM es_games WHERE platform_ID=($id) HAVING game_dev = 0 ORDER BY game_title ", ARRAY_A );
But I am already at a loss with the following main loop of the function:
while($row = mysqli_fetch_array($result)) {
or how to count the amount of rows in the query using $wpdb
$rowcount = mysqli_num_rows($result);
I can provide the full custom scripts I use if needed, I just didn’t want to post those as they are quite long =)
- The topic ‘Migrating MYSQL to $wpdb’ is closed to new replies.