duanlisha2335 2015-07-28 18:08
浏览 98

While循环中的数组,如sql fetch_array

we are using php+sqlserver with stored procedures in a project. our customer wants to put another server(lets say X server) between our application and database server. we will send requests to X and it will connect to DB and will return data to application. right now we are using 2 functions. db_request (it has sqlsrv_request) and db_fetch (it has sqlsvr_fetch_array). for example, when we select some cities, we are calling select_user_by_city procedure.

$req = db_request("select_user_by_city",array("city_id"=>1));
while($result=db_fetch($req)){blablabla}

and my problem begins on this point. i changed inside of db_request function and add some curl and json code in it. its sends the request to X server. X server calling sqlsrv_request and selecting data and returning data as json again. im converting json to array in db_fetch function in application server. but when it proceed to while loop, its going infinite loop. because returning data is not resource anymore, its an array.
is there anyway to make this thing work without change all while's to foreach ?

  • 写回答

2条回答 默认 最新

  • dongshuobei1037 2015-07-28 18:25
    关注

    The problem here is that you're looping the db_fetch every time the while loop finishes once. It most likely means db_fetch will never return false, but always an array.

    Either change db_fetch to return an array when it has no further information anymore (you probably have to save some state, so db_fetch knows when it is done) or yes, change them to foreach loops.

    评论

报告相同问题?

悬赏问题

  • ¥15 关于#hadoop#的问题
  • ¥15 (标签-Python|关键词-socket)
  • ¥15 keil里为什么main.c定义的函数在it.c调用不了
  • ¥50 切换TabTip键盘的输入法
  • ¥15 可否在不同线程中调用封装数据库操作的类
  • ¥15 微带串馈天线阵列每个阵元宽度计算
  • ¥15 keil的map文件中Image component sizes各项意思
  • ¥20 求个正点原子stm32f407开发版的贪吃蛇游戏
  • ¥15 划分vlan后,链路不通了?
  • ¥20 求各位懂行的人,注册表能不能看到usb使用得具体信息,干了什么,传输了什么数据