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

Popular posts from this blog

node.js - Node js - Trying to send POST request, but it is not loading javascript content -

javascript - Replicate keyboard event with html button -

javascript - Web audio api 5.1 surround example not working in firefox -