Solved

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

Posted on 2014-12-23
2
74 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 500 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

How to improve team productivity

Quip adds documents, spreadsheets, and tasklists to your Slack experience
- Elevate ideas to Quip docs
- Share Quip docs in Slack
- Get notified of changes to your docs
- Available on iOS/Android/Desktop/Web
- Online/Offline

Join & Write a Comment

Both Easy and Powerful How easy is PHP? http://lmgtfy.com?q=how+easy+is+php (http://lmgtfy.com?q=how+easy+is+php)  Very easy.  It has been described as "a programming language even my grandmother can use." How powerful is PHP?  http://en.wikiped…
These days socially coordinated efforts have turned into a critical requirement for enterprises.
The viewer will learn how to dynamically set the form action using jQuery.
The viewer will learn how to count occurrences of each item in an array.

758 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

Need Help in Real-Time?

Connect with top rated Experts

23 Experts available now in Live!

Get 1:1 Help Now