【发布时间】:2015-07-31 07:44:36
【问题描述】:
我给了我这个我没有看到的错误:'警告:在第 17 行的 C:\xampp\htdocs\sito\personalImage.php 中为 foreach() 提供的参数无效' 这是我的代码:
try{
$conn= new PDO("mysql:host=localhost;dbname=first","root","..");
echo "connection good";
$user=$_COOKIE['log'];
$conn->setAttribute(PDO::ATTR_ERRMODE,PDO::ERRMODE_EXCEPTION);
foreach($conn->exec('SELECT cognome FROM utenti') as $row){
}
$conn=null;
}
catch(PDOException $e){
echo $e->getMessage();
}
与数据库的连接良好。 谁能给我解释一下
【问题讨论】:
-
你确定你有结果吗?在尝试访问结果集之前检查
mysql_num_rows()。 -
这里有很多错误的东西......
-
将
or die(mysql_error())添加到mysql_query()。 -
你应该参考如何执行查询以及如何获得结果@thorny84