My input:
I feel there needs to be more interaction within the class. I feel like I'm just renaming php functions. I'm just not sure how to interact.
And, as of now, this is for PHP4.
Code: Select all
<?php
/*
* MySQL database wrapper class
*/
class db
{
/*
* @param resource $link
*/
var $link_id;
/*
* Connects to a mysql database server
* @param str $host
* @param str $username
* @param str $password
*/
function connect($host, $username, $password)
{
$this->link_id = mysql_connect($host, $username, $password) or die(mysql_error());
}
/*
* Selects a database to use on database server
* @param str $database
*/
function use_db($database)
{
mysql_select_db($database, $this->link_id);
}
/*
* Performs a query on the database and returns the result set
* @param str $sql
*/
function query($sql)
{
$result = mysql_query($sql, $this->link_id) or die(mysql_error());
return $result;
}
/*
* Gathers and returns the number of rows from a result set
* @param resource $result
*/
function num_rows($result)
{
return mysql_num_rows($result);
}
/*
* Escapes a variable for passing to a query
* @param var $variable
*/
function escape($variable)
{
return mysql_real_escape_string($variable, $link=$this->link_id);
}
/*
* Fetches a single row from a result set
* @param resource $result
* @param constant $fetch_type
*/
function fetch_row($result, $fetch_type=MYSQL_ASSOC)
{
return mysql_fetch_array($result, $fetch_type);
}
}
?>Code: Select all
if(empty($_GET['blog_id']) || !is_numeric($_GET['blog_id']))
{
$error = 'Invalid Blog Entry Specified.';
} else
{
$blog_id = $db->escape(htmlentities(stripslashes($_GET['blog_id']), ENT_QUOTES));
$result = $db->query("SELECT * FROM `blogs` WHERE `id` = '$blog_id' LIMIT 1");
if($db->num_rows($result))
{
$blog = $db->fetch_row($result);
} else
{
$error = 'Invalid Blog Entry Specified';
}
}Also, I don't want input on what I should have in there (as i haven't gotten very far yet). Just input on what I have so far.
Thank you!