/ Published in: PHP
Using Prepared Statements.
Expand |
Embed | Plain Text
Copy this code and paste it in your HTML
/* * The Prepared Statements Method * Best Practice */ $id = 5; try { $conn = new PDO('mysql:host=localhost;dbname=myDatabase', $username, $password); $conn->setAttribute(PDO::ATTR_ERRMODE, PDO::ERRMODE_EXCEPTION); $stmt = $conn->prepare('SELECT * FROM myTable WHERE id = :id'); while($row = $stmt->fetch()) { } } catch(PDOException $e) { echo 'ERROR: ' . $e->getMessage(); }
URL: http://net.tutsplus.com/tutorials/php/php-database-access-are-you-doing-it-correctly/