Monday, February 9, 2009

Prepared Statements in PHP

Example

$dbh = new PDO("mysql:dbname=".DB.";host=".HOST,USER,PASSWORD);
$sql_login = $dbh->prepare("SELECT MAX(`lastlogin`) AS `LASTLOGIN` FROM `admin_users` WHERE `user_id` <> :id");
$sql_login->execute(array(":id"=>0));
$logindetail = $sql_login->fetchAll();

$date = explode("-",$logindetail[0]['LASTLOGIN']);
$login["date"] = date("l, F j Y",mktime(0,0,0,$date[1],$date[2],$date[0]));

$space = explode(" ",$logindetail[0]['LASTLOGIN']); $time = explode(":",$space[1]);
$login["time"] = date("h:i:s A",mktime($time[0],$time[1],$time[2]));

return $login;

0 comments:

About Me

Bhargavi Moorthy
View my complete profile

FEEDJIT Live Traffic Feed