Get type specification char from MySQLi field

亡梦爱人 提交于 2019-12-11 03:22:16

问题


In MySQLi's prepared statement API, bind_param takes a type specification char.

MySQLi's fetch_field returns an object with several properties related to the field. However, the type specification char is not one of the available properties ($field->type returns an integer corresponding to a constant, not a type specification char).

What is the best way to get the type specification char from a MySQLi field?


回答1:


Just treat everything as a string, and use type s. The mysql server automatically converts strings to the column's actual datatype when processing queries, e.g. you can write things like set int_col = '32' and it will treat it as set int_col = 32.

There's a little extra overhead, since numeric data won't be transmitted in binary; the server will have to parse them. But unless you're doing a huge number of INSERT or UPDATE statements this will probably be negligible.



来源:https://stackoverflow.com/questions/14370307/get-type-specification-char-from-mysqli-field

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!