在php中实现一个执行sql update语句的函数,传入参数表名,列值对的数组和where语句。在拼sql语句的时候,是否必须要知道列的类型,是否可以所有列的值都作为字符串处理(用引号括起来)。例如:update table1 set intcol=‘999’ where id=123。这句sql是可以执行通过的,但是可以作为普遍原则吗,有没有特殊的情况?
黄舟2017-04-17 11:03:45
供参考:
mysql> create table sf (x boolean); Query OK, 0 rows affected (0.04 sec) mysql> describe sf; +-------+------------+------+-----+---------+-------+ | Field | Type | Null | Key | Default | Extra | +-------+------------+------+-----+---------+-------+ | x | tinyint(1) | YES | | NULL | | +-------+------------+------+-----+---------+-------+ 1 row in set (0.00 sec) mysql> insert into sf values ("true"), ("1"), ("false"), ("0"), (TRUE), (FALSE); Query OK, 6 rows affected, 2 warnings (0.00 sec) Records: 6 Duplicates: 0 Warnings: 0 mysql> select * from sf; +------+ | x | +------+ | 0 | | 1 | | 0 | | 0 | | 1 | | 0 | +------+ 6 rows in set (0.00 sec)