doudong0425 2018-07-08 11:18
浏览 53
已采纳

PDO - 在我的情况下,那个大的bindValue和bindParam

Yup... it's one of these.

Well, I am currently working on something that we can call a social network. I am using the Slim Framework with PDO and it's my very first job as well as my very first project. So, the problem is that I have a string in my Controller, but I want to pass it on to the model, but after it goes to the model( I've tested with print_r to see if it does pass and it does ) the bindParam doesn't seem to put it on the query.

The function would be this one:

    public static function obterTagsDasPessoas($ids)
{
    $container = getContainer();
    $query = $container->db->prepare("SELECT * FROM Pessoas_tags WHERE :ids");
    $query->bindParam(':ids', $ids, PDO::PARAM_STR);
    $query->execute();

    $result = $query->fetchAll();
    return $result;
}

I've tried changing to bindValue, since I saw that it is better for text. I don't know what's happening because it doesn't give any errors; it just doesn't seem to apply that bindParam and then procedes. Inside the $ids is id_Pessoas = 1 OR id_Pessoas = 4 which should complement the query up there. I've tried copying it to phpmyadmin and mySql and it gives me the expected results, it just doesn't work with that function.

Am I doing anything wrong? Thanks in advance.

  • 写回答

1条回答 默认 最新

  • dsa2c2255888 2018-07-08 11:36
    关注

    I think you should send a single id such as 1 or 4 in your $ids parameter.

    Then edit your query as

    $query = $container->db->prepare("SELECT * FROM Pessoas_tags WHERE id_Pessoas=:ids");

    I think this should work.

    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论

报告相同问题?

悬赏问题

  • ¥15 求指导ADS低噪放设计
  • ¥15 CARSIM前车变道设置
  • ¥50 三种调度算法报错 有实例
  • ¥15 关于#python#的问题,请各位专家解答!
  • ¥200 询问:python实现大地主题正反算的程序设计,有偿
  • ¥15 smptlib使用465端口发送邮件失败
  • ¥200 总是报错,能帮助用python实现程序实现高斯正反算吗?有偿
  • ¥15 对于squad数据集的基于bert模型的微调
  • ¥15 为什么我运行这个网络会出现以下报错?CRNN神经网络
  • ¥20 steam下载游戏占用内存