Get MySQL Query Results as Their Native Data Type?

后端 未结 5 1317
孤城傲影
孤城傲影 2020-11-30 10:03

I have tried fetching MySQL query results using mysql_fetch_row() and mysql_result() and numeric values are being returned as strings.

Is

5条回答
  •  情书的邮戳
    2020-11-30 10:47

    I've implemented this the manual way. It's actually not too bad, just a few lines.

    As suggested, call mysqli_fetch_fields() on the resource resulting from your query.

    Then from a mapping of the PHP field type numbers to MySQL data types (see industrious work here http://www.php.net/manual/en/mysqli-result.fetch-field-direct.php) you can convert your values from the wide range of database types returned as strings by MySQLi, into the appropriate type in PHP.

    How much of a slowdown it is I'm not sure tho.

提交回复
热议问题