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

  • SEARCH
  • Home
  • 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 7803947
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 2, 20262026-06-02T01:45:09+00:00 2026-06-02T01:45:09+00:00

I am developing PHP and have a simple file to test various functionality. To

  • 0

I am developing PHP and have a simple file to test various functionality. To facilitate this I would like to run this file from the command line. This is causing a problem and I’m not sure what it is.

The code makes use of PDO. I have a Database class that acts as a PDO wrapper and enforces a singleton design patter. The class is very simple. Here is some of the relevant code:

// instance of PDO
private static $db = null;

//connection related fields
const dsn = "mysql:dbname=mydb;host=localhost";
const user = "myuser";
const password = "mypass";

//get access to the PDO instance
public static function get_instance()
{
    if(!self::$db)
    {
        self::$db = new PDO(self::dsn,self::user,self::password);
        self::$db->setAttribute( PDO::ATTR_ERRMODE, PDO::ERRMODE_EXCEPTION );
        self::$db->exec("set names utf8");
    }

    return self::$db;

}

Now when I create a test file with the following:

$db = Database::get_instance();

and run it from the command line like so:

php5 ./testing.php

I get an exception:
PDOException’ with message ‘could not find driver’
this is caused by the line above that instantiates a new PDO object.

HOWEVER if I navigate to this file via my browser and it is served by my web server it runs fine, the object works as expected.

This appears to be an issue with running a PHP file from the terminal. I don’t think this is an issue in code. Could anyone suggest what could be causing this? Any advice or help would really be appreciated. Thanks.

  • 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-02T01:45:10+00:00Added an answer on June 2, 2026 at 1:45 am

    The commandline version of PHP can have a different configuration than the web-version. Locate the proper PHP configuration file, setup the database drivers and you should be fine.

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

Sidebar

Related Questions

So I have a simple Apache with MySql I am developing a PHP app.
I am developing php application with cURL library. I would like to get redirect
I am new to php and the yii framework. I have started developing simple
I am developing a website in PHP and I would like to use a
Currently developing a PHP framework and have ran into my first problem. I need
I am used to developing in PHP/MySQL and have no experience developing with SQL
I am developing a php web site. Here I have implemented clean URL using
I am developing w php web site. Here I have set a php cookie
I have read a lot of articles on developing classes (I am using php),
I have a best practice question. I'm developing a OO MVC framework in PHP,

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.