[2 days left] What’s wrong with your cloud strategy? Learn why multicloud solutions matter with Nimble Storage.Register Now

x
?
Solved

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

Posted on 2014-12-23
2
Medium Priority
?
97 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
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

[Webinar] Lessons on Recovering from Petya

Skyport is working hard to help customers recover from recent attacks, like the Petya worm. This work has brought to light some important lessons. New malware attacks like this can take down your entire environment. Learn from others mistakes on how to prevent Petya like worms.

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…
Originally, this post was published on Monitis Blog, you can check it here . In business circles, we sometimes hear that today is the “age of the customer.” And so it is. Thanks to the enormous advances over the past few years in consumer techno…
This tutorial will teach you the core code needed to finalize the addition of a watermark to your image. The viewer will use a small PHP class to learn and create a watermark.
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

656 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