Hi,
I have this bit of code and I'm wondering if I can use multiple PDOException after each execute function since there are several SELECT statements. There is an error in my PHP IDE (using nusphere) when I add in the:
catch(PDOException $e) {...}
Select all
Open in new window
after each execute()
Thank you,
Victor
/**
* Get selected product from products table for the given product_id
* @return int (success == 1), array $row[all fields from products table], int $count
* @param product_id (primary key to product_id.products)
* @access public
*/
public function getSelectedProductInfo($product_id) {
try {
/* Verify connection */
$q = "SELECT * FROM products where product_id=".$product_id;
$stmt = db::getConnect()->prepare($q);
$countTest = $stmt->execute();
//return count
$count = $stmt->rowCount();
//success
if ($count >= 1) {
$row = $stmt->fetchAll(PDO::FETCH_ASSOC);
/**
* Get product_type_name form product_types table
* (described as Category: on product-scores.php page)
* product_type.products = product_type_id.product_types
* @param int product_type.products ($row['product_type'])
*/
$product_type = $row['product_type'];
$q2 = "SELECT product_type_name FROM product_types where product_type_id=".$product_type;
$stmt2 = db::getConnect()->prepare($q2);
$stmt2->execute();
$countProdTypeName = $stmt2->rowCount(); //return count to verify
if ($countProdTypeName >= 1) {
$rowProdTypeName = $stmt2->fetchAll(PDO::FETCH_ASSOC);
}
/**
* Get brand_name form product_brands table
* (described as Brand: on product-scores.php page)
* product_brand.products = brand_id.product_brands
* @param int product_brand.products ($row['product_brand'])
*/
$product_brand = $row['product_brand'];
$q3 = "SELECT brand_name FROM product_brands where brand_id=".$product_brand;
$stmt3 = db::getConnect()->prepare($q3);
$stmt3->execute();
$countBrandName = $stmt3->rowCount(); //return count to verify
if ($countBrandName >= 1) {
$rowBrandName = $stmt3->fetchAll(PDO::FETCH_ASSOC);
}
/**
* Get sub_brand_name form product_sub_brands table
* (described as Product Line: on product-scores.php page)
* product_sub_brand.products = sub_brand_id.product_sub_brands
* @param int product_sub_brand.products ($row['product_sub_brand'])
*/
$product_sub_brand = $row['product_sub_brand'];
$q4 = "SELECT sub_brand_name FROM product_sub_brands where sub_brand_id=".$product_sub_brand;
$stmt4 = db::getConnect()->prepare($q4);
$stmt4->execute();
$countSubBrandName = $stmt4->rowCount(); //return count to verify
if ($countSubBrandName >= 1) {
$rowSubBrandName = $stmt4->fetchAll(PDO::FETCH_ASSOC);
}
return array(1, $row, $count, $rowProdTypeName, $rowBrandName, $rowSubBrandName);
}
}
catch(PDOException $e) {
$count = 0;
return array(0, $e->getMessage(), $count);
}
}
Select all
Open in new window