weixin_33726943 2015-09-01 12:10 采纳率: 0%
浏览 9

PDO查询不返回任何内容

I have a problem with my query, it returns nothing.

  if($champ == "type_id")       
            {
                $bdd = new PDO("mysql:dbname=maruecondi_db;host=localhost","root","");
                $request = $bdd->prepare('SELECT * FROM type_commercant WHERE type=:old');
                $request->execute(array(':old' => $old));
                while($row = $request->fetch())
                {
                    $bdd1 = new PDO("mysql:dbname=maruecondi_db;host=localhost","root","");
                    $request1 = $bdd1->prepare('UPDATE commercant SET type_id=:type_id WHERE id=:id');
                    $request1->execute(array(':type_id' => $row['id'],':id' => $id));
                }
            }

I'm getting variables from ajax request (JQUERY) and i initialize them before, i avoid you the code. Other requests on the page works. I have currently no way to see if somethings got wrong, due to ajax call. (No php orange boxes / pdo message) I tried to solve to problems, and i discovered that we go into the if. I deleted the first query which contains the while, i replaced $row['id'] by a value, and i worked. Since the beginning, i keep copying and pasting the connection to my database so no problem.

So my problem is here:

                $request = $bdd->prepare('SELECT * FROM type_commercant WHERE type=:old');
                $request->execute(array(':old' => $old));
                while($row = $request->fetch())

I don't see what i've done wrong...

 $request = $bdd->prepare('SELECT * FROM type_commercant');
                $request->execute();
                while($row = $request->fetch())

This works, so i tried this:

                    $request = $bdd->prepare('SELECT * FROM type_commercant');
                $request->execute();
                while($row = $request->fetch())
                {
                    if($row['type'] == $old)
                    {
                        $request1 = $bdd->prepare('UPDATE commercant SET type_id=:type_id WHERE id=:id');
                        $request1->execute(array(':type_id' => $row['id'],':id' => $id));
                    }

                }

We don't go in the condition if($row['type'] == $old), but i delete this condition, and when i replace with something like this:

while($row = $request->fetch())
                {
                        $request1 = $bdd->prepare('UPDATE commercant SET adresse=:type_id WHERE id=:id');
                        $request1->execute(array(':type_id' => $row['id'],':id' => $id));
                 }

It works... i checked $row['type'], $row['id'], $old in array(':type_id' => $row['id'], all variable got the string attented. So what's the problem? Thanks in advance !

  • 写回答

2条回答 默认 最新

  • weixin_33674437 2015-09-01 14:42
    关注

    Hmm, how to say that...

    I was updating the data with the old data i explain myself:

    $bdd = new PDO("mysql:dbname=maruecondi_db;host=localhost","root","");
                $request = $bdd->prepare('SELECT id FROM type_commercant WHERE type=:old');
                $request->execute(array(':old' => $old));
    

    was getting the old ID from type_commercant, and i was doing this:

     $request1 = $bdd1->prepare('UPDATE commercant SET type_id=:type_id WHERE id=:id');
                    $request1->execute(array(':type_id' => $row['id'],':id' => $id));
    

    So i replaced the old ID by... the old ID.

    Sorry for that mistake, thanks anyway for reading me and trying so solve this problem :D

    评论

报告相同问题?

悬赏问题

  • ¥15 spring后端vue前端
  • ¥15 寻一个支付宝扫码远程授权登录的软件助手app
  • ¥15 解riccati方程组
  • ¥15 display:none;样式在嵌套结构中的已设置了display样式的元素上不起作用?
  • ¥15 使用rabbitMQ 消息队列作为url源进行多线程爬取时,总有几个url没有处理的问题。
  • ¥15 Ubuntu在安装序列比对软件STAR时出现报错如何解决
  • ¥50 树莓派安卓APK系统签名
  • ¥65 汇编语言除法溢出问题
  • ¥15 Visual Studio问题
  • ¥20 求一个html代码,有偿