I have a function to fetch data from a table on the single-product.php template
function get_product_meta( $pid ) {
global $wpdb;
$query = $wpdb->prepare( 'SELECT * FROM wp_product_feed WHERE product_id = %d', $pid );
$var = $wpdb->get_row( $query );
return $var;
}
The issue is the server crashes from out of memory.
Anyone know why or how the best way to troubleshoot the issue? The site crashes before the page loads and cannot ssh into the server to view the logs.
UPDATED THE FUNCTION TO ONLY FETCH ONE COLUMN
function get_product_meta( $pid, $key ) {
global $wpdb;
$query = $wpdb->prepare( "SELECT `$key` FROM wp_product_feed WHERE product_id = %d", $pid );
$var = $wpdb->get_var( $query );
return $var;
}
Still having the same issue
My Answer:
>prepare( "SELECT * FROM wp_product_meta WHERE product_id = %d", $pid );_ $result = $wpdb->get_results( $query );_ return $result;_}However, when I call this function on the single-product.php template, it causes the server to run out of memory. I have tried increasing the memory limit in the php.ini file, but it still doesn't solve the issue. Is there a better way to fetch data from the database without causing memory issues?
Rate this post
5 of 5 based on 5004 votesComments