Warning: mysql_fetch_array (): Verilen argümanı geçerli bir MySQL sonuç değildir

3 Cevap php

Bu çalıştırmak çalışırken ben hata alıyorum:

<?php
require_once('includes/DbConnector.php');
$connector = new DbConnector();
$result = $connector->query('SELECT title,content FROM staff_vacancies ORDER BY ordering LIMIT 0,100');
// Get an array containing the results.
// Loop for each item in that array
while ($row = $connector->fetchArray($result)){

echo $row['title'].'</h3>';
echo $row['content'];
}
?>

DbConnector.php: Ben bağlantılı bir dosya var:

<?php
////////////////////////////////////////////////////////////////////////////////////////
// Class: DbConnector
// Purpose: Connect to a database, MySQL version
///////////////////////////////////////////////////////////////////////////////////////
require_once 'SystemComponent.php';

class DbConnector extends SystemComponent {

var $theQuery;
var $link;

//*** Function: DbConnector, Purpose: Connect to the database ***
function DbConnector(){

    // Load settings from parent class
    $settings = SystemComponent::getSettings();

    // Get the main settings from the array we just loaded
    $host = $settings['dbhost'];
    $db = $settings['dbname'];
    $user = $settings['dbusername'];
    $pass = $settings['dbpassword'];

    //the settings
    $host = 'localhost';
    $db = 'xxx';
    $user = 'xxx';
    $pass = 'xxx';

    // Connect to the database
    $this->link = mysql_connect($host, $user, $pass);
    mysql_select_db($db);
    register_shutdown_function(array(&$this, 'close'));

}

//*** Function: query, Purpose: Execute a database query ***
function query($query) {
    $this->theQuery = $query;
    return mysql_query($query, $this->link);
}

//*** Function: getQuery, Purpose: Returns the last database query, for debugging ***
function getQuery() {
    return $this->theQuery;
}

//*** Function: getNumRows, Purpose: Return row count, MySQL version ***
function getNumRows($result) {
    return mysql_num_rows($result);
}

//*** Function: fetchArray, Purpose: Get array of query results ***
function fetchArray($result) {
    return mysql_fetch_array($result);
}

//*** Function: close, Purpose: Close the connection ***
function close() {
    mysql_close($this->link);
}


}
?>

Kimse sorunun ne olduğunu biliyor mu?

3 Cevap

Sizin sorgu geçersiz kaynak olmaya $ sonuç neden olan bir sorun olması gerekir.

Eğer sorguyu çalıştırdığınız satırdan sonra mysql_error() kontrol etmeyi deneyin.

Edit:

Eğer kötü bir sorgu varsa tanımlanabilir bir hata atılır ve böylece aslında, ben, aşağıdaki gibi bir şey) (sizin DBConnector sınıf işlevi sorguyu değiştirmek istiyorsunuz:

function query($query) {
    $this->theQuery = $query;
    $queryId = mysql_query($query,$this->link);
    if (! $queryId) {
    	throw new Exception(mysql_error().".  Query was:\n\n".$query."\n\nError number: ".mysql_errno();
    }
    return $queryId;
}
// Load settings from parent class
$settings = SystemComponent::getSettings();

// Get the main settings from the array we just loaded
$host = $settings['dbhost'];
$db = $settings['dbname'];
$user = $settings['dbusername'];
$pass = $settings['dbpassword'];

//the settings
$host = 'localhost';
$db = 'xxx';
$user = 'xxx';
$pass = 'xxx';

Eğer bağlantı değişkenler atamak için demek istediniz? OR saplama kod birkaç satır çıkarmak unuttum oldu? Ya da sadece bir örnek $ ayarları ne içerdiğini göstermek için?

Mysql_error () gelen hata verin. O olmadan ben sadece tahmin edebilirsiniz ... Alan adları kaçan deneyin?

$result = $connector->query('SELECT `title`,`content` FROM `staff_vacancies` ORDER BY `ordering` LIMIT 0,100');