- html - 出于某种原因,IE8 对我的 Sass 文件中继承的 html5 CSS 不友好?
- JMeter 在响应断言中使用 span 标签的问题
- html - 在 :hover and :active? 上具有不同效果的 CSS 动画
- html - 相对于居中的 html 内容固定的 CSS 重复背景?
我正在使用准备好的语句来插入数据。我收到“参数编号无效:绑定(bind)变量的数量与标记数量不匹配。”
我已尝试转储准备好的语句,但无法发现不匹配的情况。有没有办法找出不匹配的情况。
$i = 0 ; $j = 0 ; $k = 0 ; $l = 0 ; $str = "" ; $region_str = '' ;
$occasion_str = '' ; $flavor_str = '' ;
foreach($result->WINES->WINE as $w)
{
if($i == 0)
$str = "(:wineid$i,:acctid$i,:brand$i,:varietal$i,:descr$i,:prop$i,:color$i,:case$i,:url$i)" ;
else
$str .= ", (:wineid$i,:acctid$i,:brand$i,:varietal$i,:descr$i,:prop$i,:color$i,:case$i,:url$i)" ;
foreach($w->REGIONS->REGION as $region)
{
if($j == 0)
$region_str = "(:rwineid$i,:region$j)" ;
else
$region_str .= ", (:rwineid$i,:region$j)" ;
$j++ ;
}
foreach($w->OCCASIONS->OCCASION as $o)
{
if($k == 0)
$occasion_str = "(:owineid$i,:occasion$k)" ;
else
$occasion_str .= ", (:owineid$i,:occasion$k)" ;
$k++ ;
}
foreach($w->FLAVORS->FLAVOR as $f)
{
if($l == 0)
$flavor_str = "(:fwineid$l,:flavor$l)" ;
else
$flavor_str .= ", (:fwineid$l,:flavor$l)" ;
$l++ ;
}
$i++ ;
}
$sql = " Delete from wines ;
Insert into wines (wineid,acctid,brandname,varietal,description,propreitaryname,color,caseproduction,url)
values
$str ;
Delete from wine_regions ;
Insert into wine_regions (wineid,region) values $region_str ;
Delete from wine_occasions ;
Insert into wine_occasions (wineid,occasion) values $occasion_str ;
Delete from wine_flavors ;
Insert into wine_flavors (wineid,flavor) values $flavor_str ; " ;
if($str != "")
{
$command = Yii::app()->db->createCommand($sql) ;
// $command_2 = Yii::app()->db->createCommand($sql_2) ;
$i = 0 ; $j = 0 ; $k = 0 ; $l = 0 ;
foreach($result->WINES->WINE as $wine)
{
$command->bindValue(":wineid$i",$wine->WINEID,PDO::PARAM_STR) ;
// $command_2->bindValue(":wineid$i",$i,PDO::PARAM_STR) ;
$command->bindValue(":acctid$i",$wine->ACCTID,PDO::PARAM_STR) ;
$command->bindValue(":brand$i",$wine->BRANDNAME,PDO::PARAM_STR) ;
$command->bindValue(":varietal$i",$wine->VARIETAL,PDO::PARAM_STR) ;
$command->bindValue(":descr$i",$wine->DESCRIPTION,PDO::PARAM_STR) ;
$command->bindValue(":prop$i",$wine->PROPRIETARYNAME,PDO::PARAM_STR) ;
$command->bindValue(":color$i",$wine->COLOR,PDO::PARAM_STR) ;
$command->bindValue(":case$i",$wine->CASEPRODUCTION,PDO::PARAM_STR) ;
$command->bindValue(":url$i",$wine->URL,PDO::PARAM_STR) ;
foreach((array)$wine->REGIONS->REGION as $region)
{
$command->bindValue(":rwineid$j",$wine->WINEID,PDO::PARAM_STR) ;
$command->bindValue(":region$j",$region,PDO::PARAM_STR) ;
$j++ ;
}
foreach((array)$wine->OCCASIONS->OCCASION as $o)
{
$command->bindValue(":owineid$k",$wine->WINEID,PDO::PARAM_STR) ;
$command->bindValue(":occasion$k",$o,PDO::PARAM_STR) ;
$k++ ;
}
foreach((array)$wine->FLAVORS->FLAVOR as $f)
{
$command->bindValue(":fwineid$l",$wine->WINEID,PDO::PARAM_STR) ;
$command->bindValue(":flavor$l",$f,PDO::PARAM_STR) ;
$l++ ;
}
$i++ ;
}
var_dump($command) ;
$command->execute() ;
}
最佳答案
我不检查,如果会出错 - 请在评论中告诉我。试试我的代码:
if(!empty($result->WINES->WINE))
{
$i = 0 ; $j = 0 ; $k = 0 ; $l = 0 ;
$arr = $region_arr = $occasion_arr = $flavor_arr = array();
$str = $region_str = $occasion_str = $flavor_str = array();
foreach($result->WINES->WINE as $w)
{
$t = array(
":wineid$i" => $w->WINEID,
":acctid$i" => $w->ACCTID,
":brand$i" => $w->BRANDNAME,
":varietal$i" => $w->VARIETAL,
":descr$i" => $w->DESCRIPTION,
":prop$i" => $w->PROPRIETARYNAME,
":color$i" => $w->COLOR,
":case$i" => $w->CASEPRODUCTION,
":url$i" => $w->URL,
);
$arr = array_merge($arr, $t);
$str[] = implode(',', array_keys($t));
foreach($w->REGIONS->REGION as $region)
{
$t = array(
":rwineid$j" => $w->WINEID,
":region$j" => $region,
);
$region_arr = array_merge($region_arr, $t);
$region_str[] = implode(',', array_keys($t));
$j++ ;
}
foreach($w->OCCASIONS->OCCASION as $o)
{
$t = array(
":owineid$k" => $w->WINEID,
":occasion$k" => $o,
);
$occasion_arr = array_merge($occasion_arr, $t);
$occasion_str[] = implode(',', array_keys($t));
$k++ ;
}
foreach($w->FLAVORS->FLAVOR as $f)
{
$t = array(
":fwineid$l" => $w->WINEID,
":flavor$l" => $f,
);
$flavor_arr = array_merge($flavor_arr, $t);
$flavor_str[] = implode(',', array_keys($t));
$l++ ;
}
$i++ ;
}
$sql = " Delete from wines ;
Insert into wines (wineid,acctid,brandname,varietal,description,propreitaryname,color,caseproduction,url)
values
(".implode('), (', $str).") ;
Delete from wine_regions ;
Insert into wine_regions (wineid,region) values (".implode('), (', $region_str).") ;
Delete from wine_occasions ;
Insert into wine_occasions (wineid,occasion) values (".implode('), (', $occasion_str).") ;
Delete from wine_flavors ;
Insert into wine_flavors (wineid,flavor) values (".implode('), (', $flavor_str).") ; " ;
$command = Yii::app()->db->createCommand($sql) ;
$command->bindValues($arr);
$command->bindValues($region_arr);
$command->bindValues($occasion_arr);
$command->bindValues($flavor_arr);
$command->execute() ;
}
关于mysql - 在 Yii 中查找变量和绑定(bind)标记之间的不匹配,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/19838172/
目前我的后端和前端都有 2 个 Yii 安装设置。但是在处理这个问题时,它会变得有点困惑,我想知道这是否以正确的方式完成。下面是如何设置我的文件夹结构的示例。 - backend - assets
如何禁用通知,我在 idex.php 中尝试但通知是回声,我如何禁用它。 在 php.ini 最佳答案 更新 public/index.php
很难说出这里要问什么。这个问题模棱两可、含糊不清、不完整、过于宽泛或夸夸其谈,无法以目前的形式得到合理的回答。如需帮助澄清此问题以便重新打开,visit the help center . 关闭 1
'urlManager'=>array( 'urlFormat'=>'path', 'rules'=>array( '' => array('site/page/vie
从 Yii 到 Yii 2.0 这行代码怎么写: Yii::app()->getRequest()->getRestParams() ? 最佳答案 在我看来,相当于 Yii::app()->getRe
我想使用多个调用构建查询,但在使用此代码时出现错误 $command = Yii::app()->db->createCommand() ->select('*') ->from('{
Yii中我的模型规则函数中的以下代码 public function rules() { // NOTE: you should only define rules for those att
我正在开发一个带有主数据库和多个数据库的系统,每个客户端一次。当客户填写并提交包含所有必需详细信息的表单时,将创建客户数据库及其表。 我的问题:Yii 框架是否支持动态创建数据库和表?如果是这样,是否
我知道我可以在 Yii 中注册一个新的元标记并且我知道怎么做,但是我需要 替换我设置的默认标签,因为当我在一篇文章时,我想插入 元标记中文章的简短描述; 如何管理元标记? 最佳答案 如果您使用的是最新
我尝试仅在管理模块中加载 Yii Bootstrap 扩展,但它不起作用。我假设我需要预加载它或以某种方式启动它......谢谢! class AdminModule extends CWeb
我已经建立了新的 Yii2 项目。现在我想 reorganize folder structure在“public”和“app”两个文件夹中(实际上代表 protected 文件)。 框架中的所有代码
页面 Controller 访问规则: public function accessRules() { $isadmin = User::loadUser(
代理人: agent_id (primary key) 用户: f_id (foreign key) type 我以这种方式创建了关系 public function relations() {
大家好,感谢阅读。 我想知道如何将数字格式化为货币,或者只是在末尾附加 €。我在 yii 框架的管理页面上的 gridview 中工作。 我有这个,例如 'columns'=>array(
如何禁用 Yii 的内置身份验证? (/site/login ). 我正在使用扩展程序进行身份验证并且不想让内置登录保持打开状态 - 这可能是一个安全问题。 最佳答案 我认为您可以删除站点 Contr
使用 Yii,我想删除所有不是今天的行。 我的解决方案好吗? $query = "delete from `user_login_hash` where `day`!='".(date('Y-m-d'
gridview yii如何在一列数组值中显示两个关系值 在我的模型代码中有关系 $criteria->compare('exp.ExperienceYear',$this->Experience,
是他们对的任何常用方法吗?为我的 yii 项目添加扩展 ? 如何向我的 yii 添加扩展名 请解释 步骤 最佳答案 “ 应用程序配置 ”在安装扩展时起着重要作用。默认情况下,此配置将位于 php 文件
如何在 yii 中使用场景禁用文本字段?我有 3 类帐户 super 管理员、管理员和普通用户。所有 3 类用户都有权更新有关他们的信息,但其中一个字段 accountId 只能由 super 管理员
我在 yii 中找不到太多关于将默认范围应用于模型的文档,我想知道是否有人可以解释或指出我正确的方向。 我的问题的快速版本: 是否可以向默认范围添加关系,或者默认情况下向模型上的每个 AR 搜索添加“
我是一名优秀的程序员,十分优秀!