PHP未定义变量:db

时间:2013-10-25 19:06:59

标签: php

您好我更新了我的xampp软件并在PHP中遇到了这个错误:

注意:未定义的变量:第11行的C:\ xampp2 \ htdocs \ includes \ config.php中的db

致命错误:在第11行的C:\ xampp2 \ htdocs \ includes \ config.php中的非对象上调用成员函数query()

<?php
class Database {

    public function query( $string )   {

        $q = mysql_query( $string );

        if( !$q ) {

            echo mysql_error();
            die();

        }

        return $q;
    }

    public function num( $query )   {
        return mysql_num_rows( $query );
    }

    public function assoc( $query ) {
        return mysql_fetch_assoc( $query );
    }

    public function escape( $string ) {
        return mysql_real_escape_string( $string );
    }

}

$db = new Database();

的config.php

require 'db.php';

// Remember the training slash
$domain = 'http://thiswebsite.com/';
$admin_folder = 'admin';

$connect = mysql_connect('localhost','root','password');
mysql_select_db('chat', $connect);

$find_settings = $db->query("SELECT * FROM admin_settings");
$show_settings = $db->assoc($find_settings);

if(isset($_COOKIE['account'])) {

    $cookie_query = $db->query("SELECT * FROM users WHERE uid='{$_COOKIE['account']}'");
    $user = $db->assoc($cookie_query);
    $time = time();
    $db->query("UPDATE users SET last_active='{$time}' WHERE uid='{$user['uid']}'");

    if($db->num($cookie_query) >0) {

        $loggedin = TRUE;

    } else {

        $loggedin = FALSE;
        setcookie('account', '', time()-60*60*24*365,'/');

    }

}

任何帮助都会很棒,谢谢:]

0 个答案:

没有答案