HTML and CSS Reference
In-Depth Information
abstract class Model
{
public static $db;
/**
* Creates a PDO connection to MySQL
*
* @return boolean Returns TRUE on success (dies on failure)
*/
public function __construct( ) {
$dsn = 'mysql:dbname=' . DB_NAME . ';host=' . DB_HOST;
try {
self::$db = new PDO($dsn, DB_USER, DB_PASS);
} catch (PDOExeption $e) {
die("Couldn't connect to the database.");
}
return TRUE;
}
}
The
__construct()
method attempts to create a new MySQL connection using the values you stored in
system/config/config.inc.php
and throws an
Exception
if the connection fails.
■
We're using php data Objects (pdO)
4
for database access because it provides an easy interface and makes
SQl injection virtually impossible when used properly.
Note
Adding the Header and Footer Markup
The last step before actually building one of the app's pages is to get the header and footer markup added to the app
for common use.
Starting with the simplest file, create a new file in
system/inc/
called
footer.inc.php
and insert the footer
markup you built in Chapter 7:
<footer>
<ul>
<li class="copyright">
© 2013 Jason Lengstorf & Phil Leggetter
</li><!--/.copyright-->
<li>
Part of <em>Realtime Web Apps: With HTML5 WebSocket, PHP,
and jQuery</em>.
</li>
4
Search WWH ::
Custom Search