PHP SQL Query -> boolean given - Kann nicht sein?

FrazeColder

Lt. Commander
Registriert
Okt. 2013
Beiträge
1.718
Moin zusammen,

ich habe momentan ein Problem. Und zwar möchte ich gerne meine SQL je in 100er Schritten abarbeiten, da ich sonst ein Ram exthaused error bekomme. Allerdings habe ich nun mit einmal das Problem, dass ich auf einmal diese Error Meldungen erhalte:

Code:
    PHP Warning: mysqli_num_rows() expects parameter 1 to be mysqli_result, boolean given in /var/www/vhosts/httpdocs/afterUpdate.php on line 38
    PHP Fatal error: Uncaught Error: Call to a member function fetch_assoc() on boolean in /var/www/vhosts/httpdocs/afterUpdate.php:42
    Stack trace:
    #0 {main}
    thrown in /var/www/vhosts/httpdocs/afterUpdate.php on line 42

Allerdings bin ich sehr sicher, dass ich keine booleans, sondern Werte zurückbekomme.
1. Da der Code mal funktioniert hat, ich ihn nur wegen dem Ram exthaused modifiziere
2. Da ich mir ja auch vorher die Anzahl der Rows, mit $count_values, ausgeben lasse und dort ca. 2000 Rows, was auch stimmt, zurückbekomme.

Code: (Fehler in den letzten 4 Zeilen)

Code:
<?php
    if ( ! defined('ABSPATH') ) {
        // Set up WordPress environment 
        require_once( dirname( __FILE__ ) . '/wp-load.php' );
    }
    
    unlink(("httpdocs/wp_all_import.txt"));
    
    $database_gk = new mysqli("localhost", "wordpress_8", "censored", "wordpress_6");
    
    if($database_gk->connect_errno){
    	$myfile = fopen("httpdocs/wp_all_import.txt", "w");
    	fwrite($myfile, "+++ After Update +++\n+++Couldn't connect to database_gk!+++\n\n");
    	fclose($myfile);
    }
    
    $values_gk = $database_gk->query("SELECT `ID` FROM `fWR6qIN_posts` where post_type = 'product' AND post_status = 'publish'");
    
    //$database = new mysqli("localhost", "wordpress_dc", "censored", "wordpress_5");
    
    if($database->connect_errno){
    	$myfile = fopen("httpdocs/wp_all_import.txt", "w");
    	fwrite($myfile, "+++ After Update +++\n+++Couldn't connect to database!+++\n\n");
    	fclose($myfile);
    }
    
    $count_values = mysqli_num_rows($values_gk);
    $count_values = intval($count_values);
    $myfile = fopen("httpdocs/wp_all_import.txt", "a");
    fwrite($myfile, "Starting After Import - Returned Rows: " .  $count_values . " RAM: " . memory_get_peak_usage() . "\n");
    
    $start = 0;
    $limit = 100;
    
    while($limit <= $count_values){
    
    	$values_gkw = $database_gk->query("SELECT `ID` FROM `fWR6qIN_posts` where post_type = 'product' AND post_status = 'publish' limit '$start', '$limit'");
    	$counts = mysqli_num_rows($values_gkw);
    
    	fwrite($myfile, "Entered 1. While Loop + Rows: " .$counts. "\n");

MfG und Vielen Dank
 
Vielleicht solltest Du Dir Deinen SQL-String von Zeile 37 mal ausgeben lassen. Ich vermute, der sieht anders aus, als beabsichtigt, da Du es versäumst, den String korrekt zusammen zu setzen ...

Deswegen gibt Deine Abfrage false zurück ... und das ist ja ein boolean.
 
Deine Anführungszeichen nach LIMIT stören die Ausführung, die SQL-Query ist fehlerhaft.
Versuch es mal so:

Code:
"SELECT `ID` FROM `fWR6qIN_posts` where post_type = 'product' AND post_status = 'publish' limit $start, $limit"
 

Ähnliche Themen

Zurück
Oben