Viewed   374 times

Hi i'm received the could not find driver error when trying to connect to sqlite via a php file. I've set permission to 777... PHP Version 5.2.16, i have the module install. any reason why its not finding the driver, also php.ini is showing the extension pdo.so and pdo_mysql.so installed.

PDO

PDO support enabled PDO drivers mysql

pdo_mysql

PDO Driver for MySQL, client library version 5.0.92

try {
    // Connect to the SQLite Database.
    $db = new PDO('sqlite:.subscribers.db');
} catch(Exception $e) {
    die('connection_unsuccessful: ' . $e->getMessage());
}

 Answers

3

You need

[PDO_SQLITE]
extension=pdo_sqlite.so

to be enabled, for sqlite:.subscribers.db

or, for windows:

[PHP_PDO_SQLITE]
extension=php_pdo_sqlite.dll

And ofcourse this extension in your ext directory

Saturday, August 13, 2022
 
snaaa
 
5

There's a conflict between the PHP that is used by Apache and the PHP that is linked to the command line. (It happens more often that it should to be honest).

What is typically done is:

which php

This tells you which php will be expecuted when running in the command line. e.g. /usr/bin/php

mv /usr/bin/php /usr/bin/php.old

Then link or copy the correct PHP version to an executable path:

ln -s /path/to/php/bin/php /usr/bin/php

or the following should also work.

cp /path/to/php/bin/php /usr/bin/php

Also suggested if you want to be able to manually install mods:

ln -s /path/to/php/bin/phpize /usr/bin/phpize
ln -s /path/to/php/bin/php-config /usr/bin/php-config

This way your CLI will match your webserver.

Update:

If as noted in this answer if you are using Ubuntu with multiple alternative installations of PHP you can do:

sudo update-alternatives --set php /usr/bin/php<version>
sudo update-alternatives --set phar /usr/bin/phar<version>
sudo update-alternatives --set phar.phar /usr/bin/phar.phar<version> 
sudo update-alternatives --set phpize /usr/bin/phpize<version> 
sudo update-alternatives --set php-config /usr/bin/php-config<version>
Thursday, December 22, 2022
4

The problem is actually with PDO, rather than SQLite or Laravel specifically, and in fact happens with all databases. The fact that you are getting ints from MySQL suggests you are using the mysqlnd driver, which solves this for MySQL.

The solution I went with was to explicitly cast fields in my model:

protected $casts = [
    'user_id' => 'integer'
];
Thursday, September 1, 2022
 
5

You can use

sudo apt-get install php7-mysql

or

sudo apt-get install php5-mysql

or

sudo apt-get install php-mysql

This worked for me.

Sunday, October 23, 2022
 
1

As far as I can tell, SQLite only has one setting for charset, which is on a per-database level. You can't change the encoding on the connection.

The C API has two different ways of opening a connection, either as UTF-8 or UTF-16. I would expect PHP's SQLite module (And thus PDO) to simply use the UTF-8 version. If that's correct, I would expect that a SQLite connection is always UTF-8. This means that you ought to manually encode/decode strings with utf8_encode/utf8_decode.

Also see: http://www.alberton.info/dbms_charset_settings_explained.html

Saturday, September 10, 2022
 
frabcus
 
Only authorized users can answer the search term. Please sign in first, or register a free account.
Not the answer you're looking for? Browse other questions tagged :