mysql 预处理

mysql> prepare getpdo from 'select * from pdo where id=?';

ERROR 1146 (42S02): Table 'yanruicheng.pdo' doesn't exist

mysql> prepare getpdo from 'select * from class where id=?'

    -> ;

Query OK, 0 rows affected (0.01 sec)

Statement prepared

 

mysql> set @id = 6;

Query OK, 0 rows affected (0.00 sec)

 

mysql> execute getpdo;

ERROR 1210 (HY000): Incorrect arguments to EXECUTE

mysql> execute getpdo using @id;

+----+--------+--------+--------+-------+

| id | same   | gender | salary | funbu |

+----+--------+--------+--------+-------+

|  6 | 刘备   | 男     | 8000   |  1.00 |

+----+--------+--------+--------+-------+

1 row in set (0.00 sec)

 

mysql> set @id=5;

Query OK, 0 rows affected (0.00 sec)

 

mysql> execute getpdo using @id;

+----+--------+--------+--------+-------+

| id | same   | gender | salary | funbu |

+----+--------+--------+--------+-------+

|  5 | 刘备   | 男     | 8000   |  1.00 |

+----+--------+--------+--------+-------+

1 row in set (0.00 sec)

 

mysql> set @id=5 or 1;

Query OK, 0 rows affected (0.00 sec)

 

mysql> execute getpdo using @id;

+----+--------+--------+--------+-------+

| id | same   | gender | salary | funbu |

+----+--------+--------+--------+-------+

|  1 | 刘备   | 男     | 8000   |  1.00 |

+----+--------+--------+--------+-------+

1 row in set (0.00 sec)

 

mysql>

posted @ 2019-06-14 14:12  yahn~  阅读(388)  评论(0编辑  收藏  举报