Get type specification char from MySQLi field

2019-07-21 06:00发布

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

Type specification chars

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条回答
叛逆
2楼-- · 2019-07-21 06:49

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.

查看更多
登录 后发表回答