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.