Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • Home
  • SEARCH
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 7910625
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 3, 20262026-06-03T12:56:04+00:00 2026-06-03T12:56:04+00:00

Using SQLite in PHP (thus using PDO), I have this code: try { $db

  • 0

Using SQLite in PHP (thus using PDO), I have this code:

try {
$db = new PDO("sqlite:C:\Program Files\Spiceworks\db\spiceworks_prod.db");

echo "Done.<br /><b>";

$query = "SELECT id FROM Devices LIMIT 5";

echo "Results: ";

$result = $db->query($query);

while ($row = $result->fetchArray()) {
    print_r($row)."|";
}
}
catch(PDOException $e) {  
    echo $e->getMessage();  
}

But that does not print out any data from the SQL. I know the database has data in it and the connection is valid. If I change the query to say:

$query = "SELECT BLAHid FROM FakeDevices LIMIT 5";

Nothing changes. Nothing from SQL gets printed out again, and I see no errors even though this is clearly an invalid SQL query.

In both situations, the “Done” and “Results” gets printed out okay. How can I print out SQL errors, like if the query is invalid?

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-03T12:56:06+00:00Added an answer on June 3, 2026 at 12:56 pm

    You need to tell PDO to throw exceptions. You can do that by adding the following line after you connect to the database:

    $db = new PDO("sqlite:C:\Program Files\Spiceworks\db\spiceworks_prod.db");
    $db->setAttribute(PDO::ATTR_ERRMODE, PDO::ERRMODE_EXCEPTION);
    

    That way you can catch all exceptions except for a possible problem with the first line, the database connection itself.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

How to insert new row using PHP in SQLITE in table /var/drk.db and to
I'm using PDO to access two SQLite 3 databases in PHP. I want to
I am developing an Application using PHP and SQLite. And I create a my
At a tutorial on using SQLite databases. Within this tutorial, it suggested to use
This is the query of PHP using MySQL. can anyone please convert this query
I'm using SQLite3, and the SQLite3 class that's built into PHP. The following code
Using PHP, I have a simple database that may store multiple items with the
I'm a PHP dev and I'm new to Rails but have been getting on
I have been struggling through PHP and sqlite for a bit now and I'm
I have a PHP script that checks the last time a SQLite database has

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.