【发布时间】:2017-05-13 06:32:37
【问题描述】:
这段代码非常适合 Mysqli
$sql = "SELECT * FROM 'mem_tree' ";
$res = mysqli_query($conn, $sql) or die("database error:".mysqli_error($conn));
while($row = mysqli_fetch_assoc($res)){
$data[] = $row;
}
$itemsByReference = array();
但是当我尝试使用 PDO 时它不起作用
$sql = "SELECT * FROM 'mem_tree' ";
$stmt = $dbh->prepare($sql);
$stmt->execute();
while($row = $stmt->fetchAll(PDO::FETCH_ASSOC)){
$data[] = $row;
}
$itemsByReference = array();
【问题讨论】:
-
您看到了什么错误?请粘贴您的错误
-
“它不起作用”不是问题陈述。见:stackoverflow.com/help/mcve
-
$pdo = new PDO();?观看THIS ref. Connection management。另外,在页面顶部使用error_reporting(E_ALL); ini_set('display_errors', 1);,以便 PHP 帮助处理错误 -
我在 js 树示例中使用此代码,在 PDO 代码中 js 树正在加载和加载,而在 mysqli 中它可以完美运行。