开发者

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

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜