I've been reading a lot of posts here in StackOverFlow and the documentation info at php dot net.
Here's the code I'm tryng:
Example 1
$id = 1;
$sth = $this->pdo->prepare('SELECT * FROM USERS_TABLE WHERE ID_USR = ?');
$sth->execute(array(intval($id)));
Example 2
$id = 1;
$sth = $this->pdo->prepare('SELECT * FROM USERS_TABLE WHERE ID_USR = :id');
$sth->bindParam(':id', $id, PDO::PARAM_INT);
$sth->execute();
Example 3
$id = 1;
$sth = $this->pdo->prepare('SELECT * FROM USERS_TABLE WHERE ID_USR = :id');
$sth->bindValue(':id', intval($id));
$sth->execute();
If I try this:
$sth = $this->pdo->prepare('SELECT * FROM USERS_TABLE WHERE ID_USR = 1');
$sth->execute();
I get the result I'm expecting but it's not the solution I'm looking for.
Hope you can help me, thanks in advance.
////////// EDIT 1
At the end of all of this examples I'm doing this:
$arr = $sth->errorInfo();
print_r($arr);
The return is:
Array ( [0] => 00000 [1] => [2] => )
/////////// EDIT 2
Here's the code
class User {
private $registry;
private $userId;
private $userLan;
private $fullName;
private $dob;
private $email;
private $sex;
private $nationality;
private $valid; // User valid?
private $pdo; // PDO reference
/**
* Constructor del usuario. Se puede construir de dos formas, pasando email y password o pasando una id de usuario.
* @param Registry $registry.
* @param Int $id
* @param String $email
* @param String $password
* @param String $username
* @return void
*/
public function __construct ( Registry $registry, $id, $email, $password, $username)
{
echo "constructor user with id = $id ";
$this->valid = false;
$this->registry = $registry;
if($id = 0 && $username != '' && $password != '')
{
// ...
$this->valid = true;
}
//else if($id > 0)
else
{
// $id = intval($id);
echo "second if";
$this->pdo = $registry->getObject('db')->getPdo();
try
{
$sth = $this->pdo->prepare('SELECT * FROM USERS_TABLE WHERE ID_USR = :id');
$sth->execute(array(':id' => intval($id)));
//$sth->execute(array(intval($id)));
$arr = $sth->errorInfo();
print_r($arr);
$result = $sth->fetch(PDO::FETCH_BOTH);
print_r($result);
}
catch(PDOException $e)
{
echo $e->getMessage();
}
echo "passing query";
if($sth->rowCount() ==1)
echo "yeeeha";
else
echo "not yeeha (".$sth->rowCount().") ";
// ...
$this->valid = true;
}
}