Jump to content

undefined variable


doddsey_65

Recommended Posts

can anyone help with this function. i keep getting undefined variable: link error.

 

function simple_query($fields, $table, $clause, $order)
{
    if (empty($config))
    {
        require("./config/config.php");
    }    
    if(!empty($clause))
    {
        $clause = "WHERE $clause";
    }
    if(!class_exists('db_mysqli'))
    {
        include('./includes/db_mysqli.php');
        $link = new db_mysqli;
        $link->connect($config['database']);
    }
    if(!empty($order))
    {
        $direction = $order[0];
        
        switch($direction)
        {
            case "0":
            $direction = "ASC";
            break;
            case "1":
            $direction = "DESC";
            break;
        }
        
        $order = substr($order, 1, strlen($order));
        $order = "ORDER BY $order $direction";
    }
    
    $query = $link->query("SELECT $fields //THIS LINE THROWS THE ERROR
            FROM ".TBL_PREFIX."$table
            $clause
            $order")or die(mysqli_error($link));
    
    return $query;
}

 

database class:

 

class db_mysqli
{
    public $link;
    
    function connect($settings)
    {
        require_once(dirname(dirname(__FILE__)).'/config/config.php');

        $link = new mysqli($settings['hostname'],
                            $settings['username'],
                            $settings['password'],
                            $settings['database']);
        $this->link = $link;
    }
}

 

thanks.

Link to comment
https://forums.phpfreaks.com/topic/225389-undefined-variable/
Share on other sites

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.