如果我运行以下代码:
$query = "select * from city where region = :region and country = :country";
$stmt = db->prepare($query);
$region = '06';
$country = 'ad';
$params = array(":region" => $region, ":country" => $country);
foreach ($params as $key => $value) {
$stmt->bindParam($key, $value, PDO::PARAM_STR);
}
$stmt->execute();
return $stmt->fetchAll();
我在查询日志中看到的是:
select * from city where region = 'ad' and country = 'ad'
为什么? 请注意,如果我只是像这样一个接一个地绑定参数,就不会发生这种情况:
$stmt->bindParam(':region', $region, PDO::PARAM_STR);
$stmt->bindParam(':country', $country, PDO::PARAM_STR);
答案 0 :(得分:3)
在 SLB=data.DataReader("SLB","yahoo",start,end)
Traceback (most recent call last):
File "<ipython-input-226-0cd57c0d4cbe>", line 1, in <module>
SLB=data.DataReader("SLB","yahoo",start,end)
File "C:\Users\User\Anaconda3\lib\site-
packages\pandas_datareader\data.py", line 116, in DataReader
retry_count=retry_count, pause=pause,
File "C:\Users\User\Anaconda3\lib\site-
packages\pandas_datareader\yahoo\daily.py", line 76, in read
""" read one data from specified URL """
File "C:\Users\User\Anaconda3\lib\site-
packages\pandas_datareader\base.py", line 155, in read
if isinstance(self.symbols, (compat.string_types, int)):
File "C:\Users\User\Anaconda3\lib\site-
packages\pandas_datareader\base.py", line 74, in _read_one_data
out = self._read_url_as_StringIO(url, params=params)
File "C:\Users\User\Anaconda3\lib\site-
packages\pandas_datareader\base.py", line 85, in _read_url_as_StringIO
response = self._get_response(url, params=params)
File "C:\Users\User\Anaconda3\lib\site-
packages\pandas_datareader\base.py", line 120, in _get_response
raise RemoteDataError('Unable to read URL: {0}'.format(url))
RemoteDataError: Unable to read URL:
http://ichart.finance.yahoo.com/table.csv?
s=SLB&a=0&b=1&c=2000&d=5&e=16&f=2017&g=d&ignore=.csv
语句中,您最终会覆盖绑定,而不是添加绑定。由于你有数组,你可以执行:
foreach()