For the PDO abstraction layer in PHP, rowCount () is used. The returned result is 0.

Source: Internet
Author: User
Some problems encountered during the learning of PHP, but not all of them can be solved smoothly. In the PDO abstraction layer, rowCount () is used (); when the data can be queried normally, the returned result is 0. I searched the internet for a day without a specific explanation and solution. Many friends asked, but no one answered, so let's talk about the details here.

Some problems encountered during the learning of PHP, but not all of them can be solved smoothly. In the PDO abstraction layer, rowCount () is used (); when the data can be queried normally, the returned result is 0. I searched the internet for a day without a specific explanation and solution. Many friends asked, but no one answered, so let's talk about the details here.

Some problems encountered during the learning of PHP, but not all of them can be solved smoothly. In the PDO abstraction layer, rowCount () is used (); when the data can be queried normally, the returned result is 0. I searched the internet for a day without a specific explanation and solution. Many friends asked, but no one answered, therefore, here we will talk a little bit about the specific situation and the final solution, which may not be applicable to everyone, but I hope to help my friends who have encountered the same problems and are struggling with learning.

Description:

Condition: use the $ _ SQL = "SELECT id FROM dda_ddq WHERE name = '000000' LIMIT 1"; statement to query. The query result set can be printed normally.

Symptom: rowCount () is used to print 1 locally, but 0 is printed after being uploaded to the server;

After querying the online information, find the cause of the problem:

Local test environment: 5.0.51a

Mysql 5.0.45, PHP 5.2.5 returned 1
Online test environment: 5.1.48

Mysql 5.1.30, PHP 5.1.6 returned 0

Most of the beginner friends here should understand why the local code can run normally, so there is a problem with the online code.

The solution is actually very simple. After querying the help documentation of PHP5, columnCount () is used. However, it is found that only one value is returned no matter whether there is data;

Finally, I used the statement judgment solution and barely used it. I personally think there should be a better way, but I don't know it yet;

If ($ _ st-> fetchObject ()){
Return "1 ";
} Else {
Return "";
}

Slightly optimized

Return $ _ st-> fetchObject ()? 1: 0;

Therefore, I hope to have more exchanges with my friends who are studying PHP.

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.