错误:mysql_fetch_row()期望参数1是资源,布尔值是给定的

时间:2014-11-20 22:10:51

标签: mysql boolean

大家好我真的需要帮助!有一个旧脚本,现在有了更新的mysql我有2个错误:

错误号码:2 [警告] 错误消息:mysql_fetch_row()期望参数1是资源,给定布尔值 在文件中:/home/edmajas/public_html/site/class/database/ez_sql.php 在线:472

错误号码:2 [警告] 错误消息:mysql_fetch_array()期望参数1是资源,给定布尔值 在文件中:/home/edmajas/public_html/site/class/database/ez_sql.php 在线:478

ez_sql.php文件:

<?php
require_once($_SERVER['DOCUMENT_ROOT']."/php5fix.php");

// CODE FOR THIS FILE COMES FROM THREE PLACES,
// LISTED BELOW ROUGHLY IN THE ORDER IN WHICH THEY APPEAR:

// $Id: database.php,v 1.3 2003/01/10 19:29:51 half-dead Exp $
// Original Author: Kazumi Ono
// Author Website : http://www.mywebaddons.com/ , http://www.myweb.ne.jp
// Licence Type   : GPL
// ------------------------------------------------------------------------- //


// ==================================================================
//  Author: Justin Vincent (justin@visunet.ie)
//  Web:    http://php.justinvincent.com
//  Name:   ezSQL
//  Desc:   Class to make it very easy to deal with mySQL database connections.
//
// !! IMPORTANT !!
//
//  Please send me a mail telling me what you think of ezSQL
//  and what your using it for!! Cheers. [ justin@visunet.ie ]
//
// ==================================================================


// $Id: mysql.php,v 1.9 2003/01/10 19:20:18 half-dead Exp $
// Original Author: Half-Dead
// Author Website : http://www.e-xoops.com
// Licence Type   : Proprietary
// ------------------------------------------------------------------------- //


// FROM database.php

class AbsDatabase {
    var $prefix;
    var $debug;

    function setPrefix($value='') {
        $this->prefix = $value;
    }

    function prefix($tablename='') {

    if ($tablename == '') {
        return $this->prefix;
        } else {
            if ($this->prefix == '') {
                return $tablename;
                } else {
                    return $this->prefix ."_". $tablename;
                }
        }
    }

    function setDebug($level=1) {

        if (intval($level) & 1) {
            error_reporting(2039);
        } else {
            error_reporting(0);
        }

    $this->debug = intval($level);
    }
}

// FROM ez_sql.php
define('EZSQL_VERSION',"1.25");
define('OBJECT',"OBJECT",true);
define('ARRAY_A',"ARRAY_A",true);
define('ARRAY_N',"ARRAY_N",true);

class Database extends AbsDatabase {

    var $debug_called;
    var $vardump_called;
    var $show_errors = true;
    var $num_queries = 0;

    function Database($dbuser, $dbpassword, $dbname, $dbhost)
    {
        global $xoopsConfig;

        // Edited to include possibility of persistant connection
        if ($xoopsConfig['db_pconnect']) {
            $this->dbh = @mysql_pconnect($dbhost,$dbuser,$dbpassword);
        } else {
            $this->dbh = @mysql_connect($dbhost,$dbuser,$dbpassword);
        }

        if ( ! $this->dbh ) {
            $this->print_error("<ol><b>Error establishing a database connection!</b><li>Are you sure you have the correct user/password?<li>Are you sure that you have typed the correct hostname?<li>Are you sure that the database server is running?</ol>");
        }

        $this->select($dbname);

    }

    function select($db) {
        if ( !@mysql_select_db($db,$this->dbh))
        {
            $this->print_error("<ol><b>Error selecting database <u>$db</u>!</b><li>Are you sure it exists?<li>Are you sure there is a valid database connection?</ol>");
        }
    }


    function escape($str) {
        return mysql_escape_string(stripslashes($str));
    }

    function print_error($str = "") {

        global $EZSQL_ERROR;

        if ( !$str ) $str = mysql_error();

        $EZSQL_ERROR[] = array
                        (
                            "query" => $this->last_query,
                            "error_str"  => $str
                        );

        if ( $this->show_errors ) {
            // If there is an error then take note of it
            print "<blockquote><font face=arial size=2 color=ff0000>";
            print "<b>SQL/DB Error --</b> ";
            print "[<font color=000077>$str</font>]";
            print "</font></blockquote>";
        } else {
            return false;
        }

    }

    function show_errors() {
        $this->show_errors = true;
    }

    function hide_errors() {
        $this->show_errors = false;
    }

    function flush() {
        $this->last_result = null;
        $this->col_info = null;
        $this->last_query = null;
    }


    function ez_query($query) {

        $return_val = 0;
        $this->flush();
        $this->func_call = "\$db->ez_query(\"$query\")";
        $this->last_query = $query;

        $this->result = @mysql_query($query,$this->dbh);
        $this->num_queries++;

        // If there is an error then take note of it..
        if ( mysql_error() )
        {
            $this->print_error();
            return false;
        }

        // Query was an insert, delete, update, replace
            if ( preg_match("/^\\s*(insert|delete|update|replace) /i",$query) ) {
                $this->rows_affected = mysql_affected_rows();

                // Take note of the insert_id
                if ( preg_match("/^\\s*(insert|replace) /i",$query) )
                {
                    $this->insert_id = mysql_insert_id($this->dbh);
                }

                // Return number fo rows affected
                $return_val = $this->rows_affected;


            } else {

                // Query was an select
                // Take note of column info
                $i=0;
                while ($i < @mysql_num_fields($this->result)) {
                    $this->col_info[$i] = @mysql_fetch_field($this->result);
                    $i++;
                }

                // Store Query Results
                $num_rows=0;
                while ( $row = @mysql_fetch_object($this->result) ) {
                    // Store relults as an objects within main array
                    $this->last_result[$num_rows] = $row;
                    $num_rows++;
                }

                @mysql_free_result($this->result);

                // Log number of rows the query returned
                $this->num_rows = $num_rows;

                // Return number of rows selected
                $return_val = $this->num_rows;
            }
        // If debug ALL queries
            $this->trace || $this->debug_all ? $this->debug() : null ;

            return $return_val;

        }

    function get_var($query=null,$x=0,$y=0)  {
        $this->func_call = "\$db->get_var(\"$query\",$x,$y)";

        if ( $query )  {
            $this->ez_query($query);
        }

        if ( $this->last_result[$y] )  {
            $values = array_values(get_object_vars($this->last_result[$y]));
        }

        return (isset($values[$x]) && $values[$x]!=='')?$values[$x]:null;
    }



    function get_row($query=null,$output=OBJECT,$y=0)  {

        $this->func_call = "\$db->get_row(\"$query\",$output,$y)";

        if ( $query ) {
            $this->ez_query($query);
        }

        if ( $output == OBJECT ) {
            return $this->last_result[$y]?$this->last_result[$y]:null;
        } elseif ( $output == ARRAY_A ) {
            return $this->last_result[$y]?get_object_vars($this->last_result[$y]):null;
        } elseif ( $output == ARRAY_N ) {
            return $this->last_result[$y]?array_values(get_object_vars($this->last_result[$y])):null;
        } else {
            $this->print_error(" \$db->get_row(string query, output type, int offset) -- Output type must be one of: OBJECT, ARRAY_A, ARRAY_N");
        }

    }


    function get_col($query=null,$x=0) {

        if ( $query ) {
            $this->ez_query($query);
        }

        for ( $i=0; $i < count($this->last_result); $i++ ) {
            $new_array[$i] = $this->get_var(null,$x,$i);
        }

        return $new_array;
    }

    function get_results($query=null, $output = OBJECT) {

        $this->func_call = "\$db->get_results(\"$query\", $output)";

        if ( $query ) {
            $this->ez_query($query);
        }

        if ( $output == OBJECT )
        {
            return $this->last_result;
        }
        elseif ( $output == ARRAY_A || $output == ARRAY_N )
        {
            if ( $this->last_result )
            {
                $i=0;
                foreach( $this->last_result as $row )
                {

                    $new_array[$i] = get_object_vars($row);

                    if ( $output == ARRAY_N )
                    {
                        $new_array[$i] = array_values($new_array[$i]);
                    }

                    $i++;
                }

                return $new_array;
            }
            else
            {
                return null;
            }
        }
    }

    function get_col_info($info_type="name",$col_offset=-1)
    {

        if ( $this->col_info ) {
            if ( $col_offset == -1 ) {
                $i=0;
                foreach($this->col_info as $col )  {
                    $new_array[$i] = $col->{$info_type};
                    $i++;
                }
                return $new_array;
            } else {
                return $this->col_info[$col_offset]->{$info_type};
            }

        }

    }

    function vardump($mixed='') {

        echo "<p><table><tr><td bgcolor=ffffff><blockquote><font color=000090>";
        echo "<pre><font face=arial>";

        if ( ! $this->vardump_called )
        {
            echo "<font color=800080><b>ezSQL</b> (v".EZSQL_VERSION.") <b>Variable Dump..</b></font>\n\n";
        }

        $var_type = gettype ($mixed);
        print_r(($mixed?$mixed:"<font color=red>No Value / False</font>"));
        echo "\n\n<b>Type:</b> " . ucfirst($var_type) . "\n";
        echo "<b>Last Query</b> [$this->num_queries]<b>:</b> ".($this->last_query?$this->last_query:"NULL")."\n";
        echo "<b>Last Function Call:</b> " . ($this->func_call?$this->func_call:"None")."\n";
        echo "<b>Last Rows Returned:</b> ".count($this->last_result)."\n";
        echo "</font></pre></font></blockquote></td></tr></table>".$this->donation();
        echo "\n<hr size=1 noshade color=dddddd>";

        $this->vardump_called = true;

    }

    function dumpvar($mixed) {
        $this->vardump($mixed);
    }

    function debug() {

        echo "<blockquote>";

        if ( ! $this->debug_called ) {
            echo "<font color=800080 face=arial size=2><b>ezSQL</b> (v".EZSQL_VERSION.") <b>Debug..</b></font><p>\n";
        }
        echo "<font face=arial size=2 color=000099><b>Query</b> [$this->num_queries] <b>--</b> ";
        echo "[<font color=000000><b>$this->last_query</b></font>]</font><p>";

            echo "<font face=arial size=2 color=000099><b>Query Result..</b></font>";
            echo "<blockquote>";

        if ( $this->col_info ) {

            echo "<table cellpadding=5 cellspacing=1 bgcolor=555555>";
            echo "<tr bgcolor=eeeeee><td nowrap valign=bottom><font color=555599 face=arial size=2><b>(row)</b></font></td>";


            for ( $i=0; $i < count($this->col_info); $i++ ) {
                echo "<td nowrap align=left valign=top><font size=1 color=555599 face=arial>{$this->col_info[$i]->type} {$this->col_info[$i]->max_length}</font><br><span style='font-family: arial; font-size: 10pt; font-weight: bold;'>{$this->col_info[$i]->name}</span></td>";
            }
            echo "</tr>";
            if ( $this->last_result ) {

                $i=0;
                foreach ( $this->get_results(null,ARRAY_N) as $one_row ) {
                    $i++;
                    echo "<tr bgcolor=ffffff><td bgcolor=eeeeee nowrap align=middle><font size=2 color=555599 face=arial>$i</font></td>";
                    foreach ( $one_row as $item ) {
                        echo "<td nowrap><font face=arial size=2>$item</font></td>";
                    }
                    echo "</tr>";
                }

            } else {
                echo "<tr bgcolor=ffffff><td colspan=".(count($this->col_info)+1)."><font face=arial size=2>No Results</font></td></tr>";
            }

            echo "</table>";

        } else {
            echo "<font face=arial size=2>No Results</font>";
        }
        echo "</blockquote></blockquote>".$this->donation()."<hr noshade color=dddddd size=1>";
        $this->debug_called = true;
    }

    function donation() {
        return "<font size=1 face=arial color=000000>If ezSQL has helped <a href=\"https://www.paypal.com/xclick/business=justin%40justinvincent.com&item_name=ezSQL&no_note=1&tax=0\" style=\"color: 0000CC;\">make a donation!?</a> &nbsp;&nbsp;[ go on! you know you want to! ]</font>";
    }


// BEGIN mysql.php
    function close() {
        return mysql_close($this->dbh);
    }


    function affected_rows() {

        $result = mysql_affected_rows($this->dbh);
        return $result;
    }

    function query($sql, $limit=0, $start=0) {

        if ( ($this->debug & 8) || ($this->debug & 16) ) {
            $this->query_log[] = $sql;
            } else {
                $this->query_log[] = 0;
            }

        if ( !empty($limit) ) {
            if (empty($start)) {
                $start = 0;
            }
            $sql = $sql. " LIMIT ".intval($start).",".intval($limit)."";
        }

        if ($this->debug & 16) {
            $output = count($this->query_log).": ".$sql;
            if ( function_exists('xdebug_call_function') ) {
                $output = "<b>".xdebug_call_function()."()</b><br />".$output;
            }
            $this->bg = ($this->bg == 'bg3') ? $this->bg = 'bg1' : $this->bg = 'bg3';
            echo "<div align='left' style='border-top:1px dashed #003030; padding: 3px;' class='".$this->bg."'>".$output."</div>";
        }

        $result = mysql_query($sql, $this->dbh);
        return $result;
    }

    function genId($sequence) {
        return 0;
    }

    function num_fields($resource) {
        $result = mysql_num_fields($resource);
        return $result;
    }

    function field_name($resource, $index) {
        $result = mysql_field_name($resource, $index);
        return $result;
    }


    function fetch_object($resource) {
        $result = mysql_fetch_object($resource);
        return $result;
    }

    function insert_id() {
        $result = mysql_insert_id($this->dbh);
        return $result;
    }


    function fetch_row($resource) {
        $result = mysql_fetch_row($resource);
        return $result;
    }

    function fetch_array($resource) {

        $result = mysql_fetch_array($resource);
        return $result;
    }

    function error() {
        if ($this->debug & 1) {
            $result = mysql_errno($this->dbh) . ": " . mysql_error($this->dbh);
            return $result;
        }
    }

    function field_type($resource, $offset) {
        $result = mysql_field_type($resource, $offset);
        return $result;
    }

    function num_rows($resource) {
        $result = mysql_num_rows($resource);
        return $result;
    }

}




?>

0 个答案:

没有答案