ai didi

php - SELECT(带 ? 和 $variable)返回空数组

转载 作者:行者123 更新时间:2023-12-01 00:49:05 24 4
gpt4 key购买 nike

抱歉,我不明白问题出在哪里。

这行得通

$query_select_date = "SELECT * FROM 2013Currencies WHERE DateOfCurrencyRate = '2001-03-23'";
$sql_select_date = $db->prepare($query_select_date);
$sql_select_date->execute();
$data_select_date = $sql_select_date->fetchAll(PDO::FETCH_ASSOC);

但这不起作用(获取空数组)

$query_select_date = "SELECT * FROM 2013Currencies WHERE DateOfCurrencyRate = ?";
$cdate = "'2001-03-23'";// or $cdate = "2001-03-23"; or $cdate = 2001-03-23; result is the same
$sql_select_date->execute($cdate);
$data_select_date = $sql_select_date->fetchAll(PDO::FETCH_ASSOC);

我想有一些错误,但不明白在哪里。

最佳答案

您需要将一个数组传递给执行方法:

$sql_select_date->execute(array($cdate));

希望对你有帮助

关于php - SELECT(带 ? 和 $variable)返回空数组,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/18011736/

24 4 0
文章推荐: r - 如何从数据框列表中(有效地)创建箱线图?
文章推荐: javascript - 如何将字符串中的单词与列表中的单词精确匹配?
文章推荐: jquery - 从现有 jQuery 对象中按 id 获取元素
文章推荐: Python Tika 无法读取 PDF - 无法下载 Tika Server
行者123
个人简介

我是一名优秀的程序员,十分优秀!

滴滴打车优惠券免费领取
滴滴打车优惠券
全站热门文章
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com