PHP gets data in MySQL original format

Source: Internet
Author: User
Tags php and mysql
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.

  • Related Article

    Contact Us

    The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

    If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

    A Free Trial That Lets You Build Big!

    Start building with 50+ products and up to 12 months usage for Elastic Compute Service

    • Sales Support

      1 on 1 presale consultation

    • After-Sales Support

      24/7 Technical Support 6 Free Tickets per Quarter Faster Response

    • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.