I have a small MVC framework.
In the db Class:
public static function getInstance() {
if (!self::$instance) {
//self::$instance = new PDO("mysql:host=".self::$servername.";dbname=".self::$db.", '".self::$user."', '".self::$pass."'");
// self::$instance-> setAttribute(PDO::ATTR_ERRMODE, PDO::ERRMODE_EXCEPTION);
self::$instance = new mysqli(self::$servername, self::$user, self::$pass,self::$db);
if (self::$instance->connect_error) {
die("Connection failed: " . self::$instance->connect_error);
}
}
return self::$instance;
}
In my class:
$sql = "SELECT * FROM rego_details ORDER BY ".$order." ASC";
$db = $registry->db;
$result = $db->query($sql);
I am trying to use prepared statements for security reasons and am using this statement to try it out (I know it is of not much use for this statement, but nevertheless I am using this as it is a simple statement to see if prep. statements work)
I have tried changing it to:
if(!($stmt = $db->prepare('SELECT * FROM rego_details ORDER BY ? ASC'))){
echo 'prepare failed!';
}
if(!($stmt->bind_param("s", $order))){
echo 'bind failed!';
}
$stmt->execute();
$result = $stmt->get_result();
var_dump($result);
The result is NULL
also using:
$stmt = $db->prepare('SELECT * FROM rego_details ORDER BY id ASC')
without the bind returns NULL
The unprepared statements work fine. $order is defined properly.