Skip to content

Instantly share code, notes, and snippets.

@coreymcmahon
Created February 7, 2013 11:17
Show Gist options
  • Save coreymcmahon/4730367 to your computer and use it in GitHub Desktop.
Save coreymcmahon/4730367 to your computer and use it in GitHub Desktop.
Using PDO for database access. From the article: PDO for Elegant PHP Database Access, http://www.modernphpbook.com/articles/pdo-for-elegant-php-database-access - Fig 6
<?php
$conn = new PDO('mysql:host=localhost;dbname=someDb', $username, $password);
$result = $conn->query('
SELECT * FROM myTable WHERE name = ' . $conn->quote($name) . '
');
$data = $query->fetch();
@benyitzhaki
Copy link

there is an error. $result should be replaced with $query

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment