Ajax software
Free javascripts
↑
Main Page
// return the URL
return $url;
}
// builds a link to a media file
function make_media_url($id, $name, $extension)
{
// prepare the medium name for inclusion in URL
$clean_name = _prepare_url_text ($name);
// build the keyword-rich URL
$url = SITE_DOMAIN . ‘/‘ . $clean_name . ‘-M’ . $id . ‘.’ . $extension;
// return the URL
return $url;
}
?>
10.
Create
include/database_tools.inc.php
, and type the following code. This file contains a
class named DatabaseTools, which includes common database functionality, such as opening
and closing database connections. These functions are called from other classes that need to
read data from the database.
<?php
// load configuration file
require_once(‘config.inc.php’);
// database related tools
class DatabaseTools
{
// helper function used to filter data for the database
function dbIdentifier($str)
{
$stripped = preg_replace(‘/[^A-Z0-9_.]/i’, ‘’, $str);
$tmp = preg_replace(‘/(.+?)(\.|$)/‘, ‘`\\1`\\2’, $stripped);
return $tmp;
}
// connect to the database and return the connection handler
function getConnection()
{
// connect to MySQL server
$db_link = mysql_connect(DB_HOST, DB_USER, DB_PASSWORD);
// throw a 500 error if the database couldn’t be reached
if ($db_link === false)
{
header(‘HTTP/1.0 500 Internal Server Error’);
echo ‘Sorry, the Cookie Ogre lost his beloved Cookie Ogress, went bingeing
and ate all of our cookies; consequentially, we will be closed until Friday.’;
}
// Connect to the seophp database
mysql_select_db(DB_DATABASE) or die(“Could not select database”);
268
Chapter 14: Case Study: Building an E-Commerce Store
c14.qxd:c14 10:46 268
Ajax software
Free javascripts
→