473,395 Members | 1,608 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,395 software developers and data experts.

What does PDO (MYSQL) return when there is an empty result set?

guillermobytes
Hi,

I was wondering what does PDO return when there are no records matching the query? i.e. i query for a column.name = 'John' and there is no 'John' in the table.


thanks for your answer.

guillermobytes
Mar 15 '10 #1
3 12369
Atli
5,058 Expert 4TB
Hey.

It returns an "empty" PDOStatement object, in much the same way the classic mysql_query function returns an "empty" resource.
Mar 15 '10 #2
thnaks Atli,

so how should i test that it is an emptyPDO statement?
Expand|Select|Wrap|Line Numbers
  1. $dbh = new PDO('connection info',...);
  2. $sql = 'SELECT something FROM somewhere WHERE id = inexistent';
  3. $ps = $dbh->query($sql);
  4. if ($ps->rowCount() > 0) {
  5.     $resultSet = $ps->fetchAll();
  6.     print_r($resultSet);
  7. } else {
  8.     echo 'Empty result set';
  9. }
Mar 16 '10 #3
Markus
6,050 Expert 4TB
PDOStatement::rowCount() does that for you.
Mar 16 '10 #4

Sign in to post your reply or Sign up for a free account.

Similar topics

6
by: alternativa | last post by:
Hi, I have problem with the following function - it was intended to ask a user for a 4-digits number: double ask_for_number (void) { char *notint; char s2; double entered_number;
2
by: bonk | last post by:
Hello, I am currently trying to wrap my head around what actually happens when I compile a normal (native) c++ class with the /CLR Flag in Visual C++ 2005 (C++/CLI). Suppose I have the...
2
by: tony | last post by:
Hello!! I know what an abstract class is which mean that the one of the derived class must define the abstract methods in the abstract class. So all the abstract methods in the abstarct class...
18
by: Seeker | last post by:
I essentially copied this program from K&R: #include <stdio.h> #include <stdlib.h> int main() { int c;
4
by: Michael R | last post by:
I have what seems to me a strange problem. I have a continous form, toggle buttons of a field, a text control, and a command's button caption. When I write the following in the text control's...
2
by: noagbodjivictor | last post by:
I'm filling an array with user input, I want an empty string to be returned when nothing is entered; ie return key hit twice... How do I do that?
10
by: thomas | last post by:
Hi, It's known that strdup() returns a char* type, but sometimes the following code generates warning messages. char *x = ... char *p = strdup(x); You must change it to
21
by: rahul sinha | last post by:
When you type one character and press enter, it prints two values, so it turns out that it does read "enter" from the input buffer. What does getchar actually return on reading enter? Moreover I...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
0
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.