已关闭,此问题需要更focused。目前不接受答复。
**想改善这个问题吗?**更新问题,使其仅通过editing this post关注一个问题。
4天前关闭。
Improve this question
对SQL/PHP来说很新。我有一个查询语句,它显示了Category中所有等于1到12的记录。
$dbHOST = 'mydbpath';
$dbNAME = 'mydbName';
$dbUSER = 'admin';
$dbPASS = '12345678';
$pdo = new PDO('mysql:host=' . $dbHOST . ';dbname=' . $dbNAME, $dbUSER, $dbPASS); // create connection
$stmt = $pdo->prepare("SELECT * FROM category WHERE cat_id >= 1 AND cat_id <= 12");
//you should never use *, just call each field name you are going to use
$stmt->execute(); // run the statement
$arr = $stmt->fetchAll(PDO::FETCH_ASSOC); // fetch the rows and put into associative array
print_r($arr); // print all array items, unformatted
?>
我已经在一个名为dbForgeQueryBuilder的程序中进行了测试,我从SLQ查询中得到了我需要的结果。
我不能解决的部分是在我的页面上放什么来查看数组结果,目前我有以下没有返回结果,我哪里出错了?
<?php echo print_r($arr[cat_name]); ?>
1条答案
按热度按时间hwazgwia1#