[Okta Webinar] Learn how to a build a cloud-first strategyRegister Now

x
?
Solved

Transitioning to PDO/MySQL.  SELECT and COUNT statement - Die if no records

Posted on 2014-12-23
2
Medium Priority
?
98 Views
Last Modified: 2014-12-23
How do I fix this query to die (kill script) if no results imported?


$query18 = "SELECT * FROM Download";
$conn->query($query18);       

$totalrecords=$conn->query('SELECT FOUND_ROWS()')->fetch(PDO::FETCH_COLUMN); // Get result count

Open in new window

0
Comment
Question by:lawrence_dev
2 Comments
 
LVL 58

Accepted Solution

by:
Gary earned 2000 total points
ID: 40515148
For a select it wouldn't be normal to have a try/catch, simple because the query should be correct and if there is a problem it's one time solution.
Bit different when doing inserts as you will need to know what went wrong.

But anyway
try {
    //  Your query stuff here
}
catch (PDOException $e) {
    die("Oops: " . $e->getMessage() );
}

Open in new window

0
 

Author Closing Comment

by:lawrence_dev
ID: 40515156
Thanks Gary!
0

Featured Post

Technology Partners: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Part of the Global Positioning System A geocode (https://developers.google.com/maps/documentation/geocoding/) is the major subset of a GPS coordinate (http://en.wikipedia.org/wiki/Global_Positioning_System), the other parts being the altitude and t…
It’s a season to be thankful, and we’re thankful for users like you who engage on site, solve technology problems, and network with others in the industry. What tech are we most thankful for? Keep reading.
The viewer will learn how to create and use a small PHP class to apply a watermark to an image. This video shows the viewer the setup for the PHP watermark as well as important coding language. Continue to Part 2 to learn the core code used in creat…
The viewer will learn how to create a basic form using some HTML5 and PHP for later processing. Set up your basic HTML file. Open your form tag and set the method and action attributes.: (CODE) Set up your first few inputs one for the name and …
Suggested Courses
Course of the Month19 days, 8 hours left to enroll

872 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question