问题
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