dousonghs58612 2017-02-16 21:04
浏览 41

Php / MSSQL - 循环停止

I'm having some trouble with a loop in php.

The loop is something like this:

while($item = $stmt->fetch(PDO::FETCH_ASSOC)){
//Check for a special condition, the id of that item, like if($item['id'] == X)
//for each id, theres a diferente if/else if in which I make another query to get the name
     $query_sql = "SELECT name from another_table where item_id = :id";
     $query_stmt = $handler->prepare($query_sql);
     $query_stmt->bindParam(':id',$item['id'],PDO::PARAM_INT);
     $query_stmt->execute();
//fetch the result and put it into a variable
}

The problem is that the loop seems to be working only for the first record, so it is probably erroring out somewhere in the middle. I've also noticed that if I run a query to get the count of all the user items before the loop, then the loop will also fail.

Is there any limit to how many queries you can run in mssql from php?

Thank you in advance.

EDIT: I should also say that if I don't try to make a query in the middle to get the items name, then the loop will fully work.

EDIT 2:

this is the function i'm using to get the items names:

  `function get_item_name($id){
$item_name = "SELECT szName from TABLE_WITH_NAME where wItemID = :id";
$item_name_stmt = $dbg->prepare($item_name);
$item_name_stmt->bindParam(':id', $id, PDO::PARAM_INT);
$item_name_stmt->execute();
$item_info = $item_name_stmt->fetch(PDO::FETCH_ASSOC);
$item_name_stmt = null;
return $item_info['szName'];

} `

And a print_r($item) result before running the function:

Array ( [dlID] => 3.377699720834E+15 [bStorageType] => 0 [dwStorageID] => 254 [bOwnerType] => 0 [dwOwnerID] => 9910 [bItemID] => 0 [wItemID] => 22105 [bLevel] => 24 [bCount] => 1 [bGLevel] => 0 [dwDuraMax] => 1000000 [dwDuraCur] => 999952 [bRefineCur] => 0 [dEndTime] => 2030-03-09 01:09:00 [bGradeEffect] => 5 [bMagic1] => 11 [bMagic2] => 13 [bMagic3] => 54 [bMagic4] => 0 [bMagic5] => 0 [bMagic6] => 0 [wValue1] => 100 [wValue2] => 43 [wValue3] => 130 [wValue4] => 0 [wValue5] => 0 [wValue6] => 0 [dwTime1] => 0 [dwTime2] => 0 [dwTime3] => 0 [dwTime4] => 0 [dwTime5] => 0 [dwTime6] => 0 [bGem] => 0 [wMoggItemID] => 153 )

Trying to get a print_r($item) after running get_item_name($id) function results in no print_r output.

  • 写回答

4条回答 默认 最新

  • duandange7480 2017-02-16 21:07
    关注

    Are you missing a ()?

     while($item = stmt->fetch(PDO::FETCH_ASSOC)){
    
    评论

报告相同问题?

悬赏问题

  • ¥15 装 pytorch 的时候出了好多问题,遇到这种情况怎么处理?
  • ¥20 IOS游览器某宝手机网页版自动立即购买JavaScript脚本
  • ¥15 手机接入宽带网线,如何释放宽带全部速度
  • ¥30 关于#r语言#的问题:如何对R语言中mfgarch包中构建的garch-midas模型进行样本内长期波动率预测和样本外长期波动率预测
  • ¥15 ETLCloud 处理json多层级问题
  • ¥15 matlab中使用gurobi时报错
  • ¥15 这个主板怎么能扩出一两个sata口
  • ¥15 不是,这到底错哪儿了😭
  • ¥15 2020长安杯与连接网探
  • ¥15 关于#matlab#的问题:在模糊控制器中选出线路信息,在simulink中根据线路信息生成速度时间目标曲线(初速度为20m/s,15秒后减为0的速度时间图像)我想问线路信息是什么