Forum Moderators: coopster

Message Too Old, No Replies

help me pls with the classes

i m using Mysql and php on my website

         

malik112

4:04 am on Apr 2, 2009 (gmt 0)

10+ Year Member



can someone please check the code for my catalog.inc.php in the include folder for the right syntax etc. i have been getting a 404 on many of my pages and i seriously think that its a problem with class definitions. Please check for "Database class to handle products" in particular. Thanks in advance:

<?php
// load configuration file
require_once('config.inc.php');
// load database tools
require_once('database_tools.inc.php');

// Database class for handling brands
class Brands
{

// retrieve cloaking data filtered by the supplied parameters
function get($id = 0, $name = '', $order_by = '', $order_dir = '')
{
// by default, retrieve all records
$q = " SELECT brands.* FROM brands WHERE TRUE ";

// filter by brand ID
if ($id) {
$id = (int) $id;
$q .= " AND id = $id ";
}

// filter by brand name
if ($name) {
$name = mysql_escape_string($name);
$q .= " AND name = '$name' ";
}

// add sorting options
if ($order_by) {
if ($order_dir !== '' && !$order_dir) {
$order_q = ' DESC ';
} else {
$order_q = ' ';
}
$q .= " ORDER BY " . db_identifier($order) . $order_q;
}

// get a database connection
$db_link = DatabaseTools::getConnection();

// execute the query
$query_results = mysql_query($q);

// close database connection
DatabaseTools::closeConnection($db_link);

// return the results as an associative array
$rows = array();
while ($result = mysql_fetch_assoc($query_results)) {
$rows[] = $result;
}
return $rows;
}

}

// Database class for handling categories
class Categories
{
// retrieves categories data filtered by the supplied parameters
function get($id = 0, $name = '', $order_by = '', $order_dir = '')
{
// by default, retrieve all records
$q = " SELECT categories.* FROM categories WHERE TRUE ";

// filter by category id
if ($id) {
$id = (int) $id;
$q .= " AND id = $id ";
}

// filter by category name
if ($name) {
$name = mysql_escape_string($name);
$q .= " AND name = '$name' ";
}

// add sorting options
if ($order_by) {
if ($order_dir !== '' && !$order_dir) {
$order_q = ' DESC ';
} else {
$order_q = ' ';
}
$q .= " ORDER BY " . DatabaseTools::dbIdentifier($order_by) . $order_q;
}

// get a database connection
$db_link = DatabaseTools::getConnection();

// execute the query
$query_results = mysql_query($q);

// close database connection
DatabaseTools::closeConnection($db_link);

// return the results as an associative array
$rows = array();
while ($result = mysql_fetch_assoc($query_results)) {
$rows[] = $result;
}
return $rows;
}
}

// Database class for handling products
class Products
{
// retrieves products data filtered by the supplied parameters
function get($id = 0, $category_id = 0, $brand_id = 0, $name = '')
{
// by default, retrieve all records
$q = "SELECT products.* FROM products WHERE TRUE ";

// filter by ID if the $id parameter was provided
if ($id) {
$id = (int) $id;
$q .= " AND id = $id ";
}

// filter by product name if the $name parameter was provided
if ($name) {
$name = mysql_escape_string($name);
$q .= " AND name = '$name' ";
}

// filter by category ID if the category_id parameter was provided
if ($category_id) {
$category_id = (int) $category_id;
$q .= " AND (SELECT COUNT(*) FROM product_categories " .
" WHERE product_categories.product_id = products.id " .
" AND product_categories.category_id = $category_id) ";
}

// filter by brand ID if the $brand_id parameter was provided
if ($brand_id) {
$brand_id = (int) $brand_id;
$q .= " AND brand_id = $brand_id ";
}

// get a database connection
$db_link = DatabaseTools::getConnection();

// execute the query
$query_results = mysql_query($q);

// close database connection
DatabaseTools::closeConnection($db_link);

// return the results as an associative array
$rows = array();
while ($result = mysql_fetch_assoc($query_results)) {
$rows[] = $result;
}
return $rows;
}
}
?>

coopster

7:56 pm on Apr 7, 2009 (gmt 0)

WebmasterWorld Administrator 10+ Year Member



Because of the nature of your code here it is going to be impossible to troubleshoot query syntax. If I were you, I would check the log for the date/time of the 404 and then refer to the MySQL query log for the same timestamp to see what query was executed. If you are not running the log, start it up for a short period of time so you can monitor failed queries.