select 语句后面的那个引号是多余的

解决方案 »

  1.   

    你那个是利用web页面来传参数的吧,如果是的话,你先把你得到的,要传给数据库执行的SQL语句打印出来,看看是不是:select * from book where title like %qq%;这样的语句。
    mysql> use test;
    Database changed
    mysql> create table test(id int not null auto_increment primary key,
        -> title varchar(20) not null);
    Query OK, 0 rows affected (0.14 sec)mysql> insert into test(title) values('qq'),('123'),('2'),('1'),('3'),('c++');
    Query OK, 6 rows affected (0.08 sec)
    Records: 6  Duplicates: 0  Warnings: 0mysql> select * from test;
    +----+-------+
    | id | title |
    +----+-------+
    |  1 | qq    |
    |  2 | 123   |
    |  3 | 2     |
    |  4 | 1     |
    |  5 | 3     |
    |  6 | c++   |
    +----+-------+
    6 rows in set (0.00 sec)
    mysql> prepare stmt from 'select * from test where title like ?';
    Query OK, 0 rows affected (0.00 sec)
    Statement preparedmysql> set @a='%1%';
    Query OK, 0 rows affected (0.00 sec)mysql> execute stmt using @a;
    +----+-------+
    | id | title |
    +----+-------+
    |  2 | 123   |
    |  4 | 1     |
    +----+-------+
    2 rows in set (0.00 sec)mysql> set @b='%qq%';
    Query OK, 0 rows affected (0.00 sec)mysql> execute stmt using @b;
    +----+-------+
    | id | title |
    +----+-------+
    |  1 | qq    |
    +----+-------+
    1 row in set (0.00 sec)