Long Integer type problems encountered when querying MongoDB in php

Source: Internet
Author: User
The problem that plagued me for a day. The first is the Mongodb replica set. Check the php Mongo extension manual to complete the replica set. Then there is a long integer problem. The timestamp of the Long Integer type stored in mongo is java. Php is a weak language with 11 timestamps. Currently, it is still in the 10-bit phase. The timestamp converted to java must be followed by zero. Generate ja

The problem that plagued me for a day. The first is the Mongodb replica set. Check the php Mongo extension manual to complete the replica set. Then there is a long integer problem. The timestamp of the Long Integer type stored in mongo is java. Php is a weak language with 11 timestamps. Currently, it is still in the 10-bit phase. The timestamp converted to java must be followed by zero. // Generate ja

The problem that plagued me for a day. The first is the Mongodb replica set. Check the php Mongo extension manual to complete the replica set. Then there is a long integer problem.

The timestamp of the Long Integer type stored in mongo is java. Php is a weak language with 11 timestamps. Currently, it is still in the 10-bit phase. The timestamp converted to java must be followed by zero.

// Generate the java timestamp $ time = (string) $ time. '000'; $ time = (int) $ time;

However, the query results have no data at all. Use Debug to print the query statement of the Framework Mongo. It is okay to directly query the statement in shell. But there is no data.
Then, the Mongo log is opened and adjusted to 5, which records the query statement. Refer to here.

I found that all the time I queried has changed to a negative number:"{$ Gt:-154503944}"

Then the omnipotent google found the answer. Php's long integer type needs to be converted using the objective int64 class. Although you output the same results in php, the query results are different. Then, add a sentence after the preceding statement.

// A required step to convert a persistent integer into a 64-bit integer $ time = new converted int64 ($ time );

Mongo extension class reference here: http://www.php.net/manual/en/mongoint64.construct.php

Original article address: php queries MongoDB for long integer data. Thank you for sharing it with the original author.

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.