doddsey_65 Posted January 23, 2011 Share Posted January 23, 2011 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 More sharing options...
trq Posted January 23, 2011 Share Posted January 23, 2011 You only create $link if db_mysql doesn't already exist, if it does exist, $link doesn't actually exist outside of the db_mysql class. Your function also has a $config variable which doesn't exist. Link to comment https://forums.phpfreaks.com/topic/225389-undefined-variable/#findComment-1163924 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.