Last active
December 12, 2015 06:38
-
-
Save coreymcmahon/4730290 to your computer and use it in GitHub Desktop.
A naive model implementation. From the article: PDO for Elegant PHP Database Access, http://www.modernphpbook.com/articles/pdo-for-elegant-php-database-access - Fig 1
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
class UserModel | |
{ | |
public static function connectDb() | |
{ | |
mysql_connect('localhost', 'username', 'password') | |
or die('some error'); | |
mysql_select_db('someDb') | |
or die('could not select db'); | |
} | |
public static function getUser($id) | |
{ | |
$db = self::connectDb(); | |
$query = 'SELECT * FROM users WHERE id = ' . (int)$id; | |
$result = mysql_query($query); | |
return mysql_fetch_object($result) | |
} | |
/* ...etc */ | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
ew ugly. have you ever heard of PDO?