[php] function reqQuery()
{
global $datalink;
$this->setUid(1);
$this->setData(‘username’);
$stmt = $datalink->prepare(‘SELECT :reqData FROM user_details where id = :reqUid limit 1’);
$stmt->bindParam(’:reqData’,$this->reqData(),PDO::PARAM_STR);
$stmt->bindParam(’:reqUid’,$this->reqUid,PDO::PARAM_INT);
echo ‘SELECT ‘.$this->reqData().’ FROM user_details where id = ‘.$this->reqUid().’ limit 1’;
try {
$stmt->execute();
}
catch (Exception $e)
{
$this->err->report_error($e,TRUE);
}
$stmt->bindColumn(‘username’,$tmp);
var_dump($stmt->fetch(PDO::FETCH_OBJ));
}[/php]
Whats returned from this:
SELECT username FROM user_details where id = 1 limit 1 //Echo statment
bool(false) // Var Dump
But when i change
[php]$stmt = $datalink->prepare(‘SELECT :reqData FROM user_details where id = :reqUid limit 1’);
$stmt->bindParam(’:reqData’,$this->reqData(),PDO::PARAM_STR);
$stmt->bindParam(’:reqUid’,$this->reqUid,PDO::PARAM_INT);[/php]
To
[php]
$stmt = $datalink->prepare(‘SELECT username FROM user_details where id = 1 limit 1’);
//$stmt->bindParam(’:reqData’,$this->reqData(),PDO::PARAM_STR);
//$stmt->bindParam(’:reqUid’,$this->reqUid,PDO::PARAM_INT);[/php]
I get:
SELECT username FROM user_details where id = 1 limit 1
object(stdClass)#8 (1) { [“username”]=> string(9) “Christina” }
So am i using bindparam wrong/how should i use it?
[php]var_dump($this->reqData());
var_dump($this->reqUid());[/php]
returns
string(8) “username”
int(1)