When I was using PHP to manipulate MySQL, all the data I got was a string, and I now want to get the data stored by MySQL, which is consistent with the type defined in MySQL, can I do that?
Reply content:
When I was using PHP to manipulate MySQL, all the data I got was a string, and I now want to get the data stored by MySQL, which is consistent with the type defined in MySQL, can I do that?
//try$pdo->setAttribute(PDO::ATTR_EMULATE_PREPARES, false); $pdo->setAttribute(PDO::ATTR_STRINGIFY_FETCHES, false);
There is a general idea, to SHOW COLUMNS FROM table_name
get the data type, define a set of PHP and MySQL data type correspondence, loop data according to the corresponding relationship to the data in turn escaped, do not know whether it is feasible.
First of all, I won't PHP
But I strongly doubt your statement php操作mysql的时候, 取得的所有数据都是字符串
.
Second, MySQL data type, is a set of MySQL mechanism, PHP data type, is a set of PHP mechanism, the two are independent, but can be mapped, but probably not all of the MySQL data types can find a matching type in PHP.
Just Var_dump tried, and it was all string type.
However, PHP is a weakly typed language, and personal feelings can most often not be concerned with data types. Just use it directly.
PHP MySQL driver By default will be the value of the field string
, so you need to go after the removal.
This is done in the PHP framework now orm
, making a conversion based on the field type.
What frame did you use? The data used by the ORM?
I'll do the formatting again.