programing

경고: mysql_fetch_array(): 제공된 인수가 올바른 MySQL 결과가 아닙니다.

magicmemo 2023. 7. 30. 17:35
반응형

경고: mysql_fetch_array(): 제공된 인수가 올바른 MySQL 결과가 아닙니다.

실행하려고 하면 다음 오류가 발생합니다.

<?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:

<?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);
}


}
?>

뭐가 문제인지 아는 사람?

쿼리에 문제가 있어 $result가 잘못된 리소스가 되어야 합니다.

쿼리를 실행한 줄 뒤에 mysql_error()를 확인해 보십시오.

편집:

사실, 저는 당신의 DB 커넥터 클래스 함수 쿼리()를 다음과 같은 것으로 변경하여 당신이 잘못된 쿼리를 가질 때 식별 가능한 오류가 발생하도록 하겠습니다.

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;
}

저는 이것을 게시물에서 발견했고, 저에게 제 문제를 해결했습니다.슬드스.

네, 답변은 간단합니다. 사용된 쿼리는 말하자면 getrow 내부의 쿼리이기 때문에 실제 결과가 아닙니다.다음은 해결 방법입니다. 다음과 같은 모든 선을 찾습니다.

mysql_fetch_array(mysql_query("...snip...";-) );

그리고 "@"를 앞에 추가하면 다음과 같습니다.

@mysql_fetch_array(mysql_query("...snip...";-) );

그런 다음 다음 행에 대해 동일한 작업을 수행합니다.코드:

mysql_num_rows(mysql_query("...snip...";-) );

"@"를 추가하여 위와 동일한 단계를 수행합니다.

@mysql_num_rows(mysql_query("...snip...";-) );

이 모든 것이 "Yyy 내에서 xxx를 수행하는 동안"으로 표시됩니다. 그렇지 않으면 결과 값이 누락되어 비활성화됩니다.그것은 PHP 같은 것입니다.

매력적으로 작동했고, 전체 코드를 찢어 모던빌에 모두 적용하는 데 5분이 걸렸습니다. 동일한 데이터베이스를 공유하고 저에게 완벽하게 작동합니다.

이 오류는 쿼리가 실패했음을 의미합니다.mysql_query() 오류가 발생하면 false를 반환하고 오류 메시지를 트리거하는 false를 전달합니다.

테이블 또는 필드가 없거나 잘못되어 쿼리가 실패할 수 있습니다.자세한 오류를 보려면 mysql_error() 결과를 출력합니다.

mysql_*라이브러리가 더 이상 사용되지 않습니다.또는 PDO로 업그레이드하는 것이 좋습니다.

// 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';

연결 변수를 다시 할당하라는 의미였습니까?아니면 빼놓는 걸 잊어버린 스텁 코드 몇 줄이었나요?아니면 $settings에 포함된 내용을 보여주는 예시일 뿐입니까?

mysql_error()의 오류를 제공하십시오.그게 없다면 난 추측할 수 밖에...당신의 필드 이름에서 벗어나려고 시도합니까?

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

쿼리에 문제가 있어 $result가 잘못된 리소스가 되어야 합니다.

사용

<?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

if($result){
while ($row = $connector->fetchArray($result)){

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

언급URL : https://stackoverflow.com/questions/795746/warning-mysql-fetch-array-supplied-argument-is-not-a-valid-mysql-result

반응형