php - PDOStatement::execute, How to execute? -
how execute query?
$pdo = database::connect(); $pdo->setattribute(pdo::attr_errmode, pdo::errmode_exception); $sql = "select * attendancy user_id = $user_id , date = '$date'"; $q = $pdo->prepare($sql);
to execute
need use execute function. usage of prepare
function not safe, each variable should placeholder.
$pdo = database::connect(); $pdo->setattribute(pdo::attr_errmode, pdo::errmode_exception); $sql = "select * attendancy user_id = ? , date = ?"; $q = $pdo->prepare($sql); $q->execute(array($user_id, $date)); while($result = $q->fetch(pdo::fetch_assoc)) { print_r($result); }
Comments
Post a Comment