This question already has an answer here:
I've migrated a really old website to a new server but I'm getting
Fatal error: Call to undefined function mysql_query() on the website
I know this is because the mysql_query has been deprecated now but I'm not clear on how to use the mysqli_query - I've tried replacing mysql_query to mysqli_query, but the mysqli_query requires 2 parameters, 1 the connection and the other query. The thing is how to get the database connection, in the code there is no mention of the database connection.
The error code, Fatal error: Call to undefined function mysql_query() on the website - I believe relates to this $results = mysql_query($query);
Any help would be most appreciated, thank you
function rs_testimonials_widgit(){
// Required for all WordPress database manipulations
global $wpdb;
// Grabbing DB prefix and settings table names to variable
$testimonials = $wpdb->prefix . "rstestimonials";
$testimonials_settings = $wpdb->prefix . "rstestimonials_settings";
$siteurl = get_option('siteurl');
//$imgurl = $siteurl . '/wp-content/plugins/' . basename(dirname(__FILE__)) . '/i/images/star-5.png';
//$imgHtml = '<img src="'. $imgurl .'" border="0" align="absmiddle" style="decoration:none;">';
$aggTestimonials = '';
$min_rating = $wpdb->get_row("SELECT value FROM $testimonials_settings WHERE name='min_rating'", ARRAY_A);
$min_rating = $min_rating['value'];
$show_3rdparty = $wpdb->get_row("SELECT value FROM $testimonials_settings WHERE name='show_3rdparty'", ARRAY_A);
$show_3rdparty = $show_3rdparty['value'];
$testimonial_num = $wpdb->get_row("SELECT value FROM $testimonials_settings WHERE name='testimonial_num'", ARRAY_A);
$testimonial_num = $testimonial_num['value'];
$is_review = $wpdb->get_row("SELECT value FROM $testimonials_settings WHERE name='is_review'", ARRAY_A);
$is_review = $is_review['value'];
$microdata_type = $wpdb->get_row("SELECT value FROM $testimonials_settings WHERE name='microdata_type'", ARRAY_A);
$microdata_type = $microdata_type['value'];
// New query adds in status checking to ensure we are only grabing the public testimonials!
if($show_3rdparty == 1){
$query = "SELECT DISTINCT id, status, featured, date, name, location, quote, website, summary, rating, 3rdparty, 3rdpartysite FROM $testimonials WHERE status!='1' AND status!='2' AND rating >= $min_rating ORDER BY RAND() LIMIT $testimonial_num";
}
else{
$query = "SELECT DISTINCT id, status, featured, date, name, location, quote, website, summary, rating, 3rdparty, 3rdpartysite FROM $testimonials WHERE status!='1' AND status!='2' AND rating >= $min_rating AND 3rdparty = '0' ORDER BY RAND() LIMIT $testimonial_num";
}
$results = mysql_query($query);
$aggrating = 0;
$theTestimonials.='<ul>';
while ($data = mysql_fetch_array($results)){
// Setting the testimonial information to variables for easy access
$name = stripslashes($data['name']);
$date = stripslashes($data['date']);
$location = stripslashes($data['location']);
if (!empty($location)){
$location = ", ".$location;
}
$quote = stripslashes($data['quote']);
$words = explode(' ', $quote);
$number_of_words=10;
if(count($words)>$number_of_words)
{
$quote='';
for($i=0;$i<$number_of_words;$i++)
{
$quote.= $words[$i].' ';
}
$quote.='...';
}
$summary = stripslashes($data['summary']);
$websitepre = '';
$websitesuf = '';
$website = $data['website'];
if (!empty($website)){
$websitepre = '<a href="'.$website.'">';
$websitesuf = '</a>';
}
$rating = $data['rating'];
$imgurl = $siteurl . '/wp-content/plugins/' . basename(dirname(__FILE__)) . '/i/images/star-'. $rating .'.png';
$imgHtml = '<img src="'. $imgurl .'" border="0" align="absmiddle" style="decoration:none;">';
// Getting prefix, suffix and company name from database
$testimonial_prefix = $wpdb->get_row("SELECT value FROM $testimonials_settings WHERE name='testimonial_prefix'", ARRAY_A);
$testimonial_prefix = $testimonial_prefix['value'];
$testimonial_suffix = $wpdb->get_row("SELECT value FROM $testimonials_settings WHERE name='testimonial_suffix'", ARRAY_A);
$testimonial_suffix = $testimonial_suffix['value'];
$company = $wpdb->get_row("SELECT value FROM $testimonials_settings WHERE name='company_name'", ARRAY_A);
$company = $company['value'];
$show_stars = $wpdb->get_row("SELECT value FROM $testimonials_settings WHERE name='show_stars'", ARRAY_A);
$show_stars = $show_stars['value'];
$show_summary = $wpdb->get_row("SELECT value FROM $testimonials_settings WHERE name='show_summary'", ARRAY_A);
$show_summary = $show_summary['value'];
$show_date = $wpdb->get_row("SELECT value FROM $testimonials_settings WHERE name='show_date'", ARRAY_A);
$show_date = $show_date['value'];
$pdate = date("Y-m-d", strtotime($date));
$disdate = date("M j, Y", strtotime($date));
if($show_date == 1){
$ddate = '<meta itemprop="datePublished" content="' . $pdate .'">'. $disdate .'</meta>';
}
else
{
$ddate = '';
}
if($show_stars == 1){
$stars = '<div itemprop="reviewRating" itemscope itemtype="http://schema.org/Rating"><meta itemprop="ratingValue" content="'. $rating .'" />'. $imgHtml .'</div> ';
}
else
{
$stars = '<div itemprop="reviewRating" itemscope itemtype="http://schema.org/Rating"><meta itemprop="ratingValue" content="'. $rating .'" /></div> ';
}
if($show_summary == 1){
$ssummary = '<span itemprop="name"><strong>'. $summary .'</strong></span> ';
}
else
{
$ssummary = '';
}
if($show_summary ==1 || $show_stars ==1){
$ssummary .= '<br /><br />';
}
// Final HTML Output
$theTestimonials .= '<li>'.$testimonial_prefix . '<div class="pad_fix" itemprop="reviews" itemscope itemtype="http://schema.org/Review">' . $stars . $ssummary . '<span itemprop="description">'. $quote . '</span><br /><br />— <strong>' . $websitepre . '<span itemprop="author">' . $name . '</span>' . $websitesuf . '</strong><em>' . $location . '</em> '. $ddate .'</div>' . $testimonial_suffix.'</li>' ;
}
$theTestimonials.='</ul><div style="clear:both;"></div>';
mysql_free_result($results);
if($show_3rdparty == 1){
$query = "SELECT rating FROM $testimonials WHERE status!='1' AND status!='2' AND rating >= $min_rating";
}
else{
$query = "SELECT rating FROM $testimonials WHERE status!='1' AND status!='2' AND featured!='1' AND rating >= $min_rating AND 3rdparty = '0'";
}
$results = mysql_query($query);
$num_rows = mysql_num_rows($results);
while ($data = mysql_fetch_array($results)){
$rating = $data['rating'];
$aggrating += $rating;
}
if($num_rows > 0){
$aggrating = ($aggrating / $num_rows);
}
$aggrating = round($aggrating, 1);
$aggTestimonial .= '<div id="aggTestimonial"><span itemprop="name">' . $company . '</span> is rated <span itemprop="aggregateRating" itemscope itemtype="http://schema.org/AggregateRating"><span itemprop="ratingValue">'. $aggrating .'</span>/5 based on <span itemprop="reviewCount">'. $num_rows .'</span> '. $is_review .'s.</span></div>';
mysql_free_result($results);
wp_reset_query();
if (is_front_page() || $testimonial_num > 1){
$final_display = '<div itemscope itemtype="http://schema.org/'.$microdata_type.'">' . $theTestimonials . $aggTestimonial .'</div>';
}
else{
$final_display = '<div itemscope itemtype="http://schema.org/'.$microdata_type.'">' . $theTestimonials .'<span itemprop="name">' . $company . '</span></div>';
}
// Let's echo it to the screen baby!
echo $final_display;
}
</div>