-1

我正在开发搜索,但出现错误:

Fatal error: Uncaught exception 'PDOException' with message 'SQLSTATE[HY093]: Invalid parameter number: number of bound variables does not match number of tokens'       
in /home/a5350289/public_html/busca.php:26 Stack trace: #0 /home/a5350289/public_html/busca.php(26): PDOStatement->execute() #1 {main} thrown in /home/a5350289/public_html/busca.php on line 26

我的代码是:

if($_GET['s']<>''){

    $explode = explode(' ',$_GET['s']);
    $num = count($explode);

    for($i=0;$i<$num;$i++){
        $busca .= " `nome` LIKE :$busca$i  OR `district` LIKE :$busca$i OR `city` LIKE :$busca$i OR `area` LIKE :$busca$i ";

        if($i<>$num-1){ $busca .= ' AND '; }

        }

        $buscar = DB::getConn()->prepare("SELECT * FROM `users` WHERE $busca");

        for($i=0;$i<$num;$i++){
            $buscar->bindValue(":busca$i",'%'.$explode[$i].'%',PDO::PARAM_STR);
        }

        $buscar->execute();

    }
                if($buscar->rowCount()>0){
                    echo '<ul id="resbusca">';
                    while($resbusca=$buscar->fetch(PDO::FETCH_ASSOC)){

        echo '<li><span><img src="uploads/usuarios/'.$resbusca['foto'].'" /></span>
        <h2><a href="perfil.php?uid='.$resbusca['id'].'">'.$resbusca['nome'].'</a></h2>
        <p>'.$resbusca['area'].'. '.$resbusca['street'].', '.$resbusca['number'].'.'.$resbusca['district'].' - '.$resbusca['city'].' / '.$resbusca['state'].'</p>
        </li>';


                    }
                    echo '</ul>';
                }else{
                echo '<div align="center" style="margin-top:200px"><h1>Sem resultados</h1></div>';

            }

        ?>
4

1 回答 1

0

如果要使用多个命名占位符来匹配单个变量,则必须打开仿真模式。
或者你必须使占位符独一无二。

于 2013-09-07T08:16:25.597 回答