Skip to content

Instantly share code, notes, and snippets.

@coreymcmahon
Last active December 12, 2015 06:38
Show Gist options
  • Save coreymcmahon/4730290 to your computer and use it in GitHub Desktop.
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
<?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 */
}
@k1ng440
Copy link

k1ng440 commented Feb 7, 2013

ew ugly. have you ever heard of PDO?

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