Do I always need to use mysql_fetch
I seem to always use these lines when i am doing a select in PHP
$product_query = "Select ProductID from productinfo where PartName = '".mysql_real_escape_string($data[0])."'";
$product_result = mysql_query($product_query) ;
$product = mysql_fetch_assoc($product_result) ;
$my_product_id = $product['ProductID开发者_StackOverflow社区'];
This works but it clutters the page so i was wondering if there an way to do this in a more concise manner
You can make your own class which just returns the data after you give it the query.
$db = new Db;
$data = $db->query('blah');
print_r($data);
You can also use PDO, which has a similar, cleaner and safer API:
http://www.phpro.org/tutorials/Introduction-to-PHP-PDO.html
精彩评论