I am deploying a Laravel project to a shared hosting and added a php.ini with:
extension=pdo.so
extension=pdo_sqlite.so
extension=sqlite.so
In phpinfo, I could also see that the sqlite extensions are loaded. Testing to connect to the database with the following code snippets also worked:
<?php
try {
$dbh = new PDO("sqlite:app/database/production.sqlite");
echo "Connected to database!";
}
catch(PDOException $e)
{
echo $e->getMessage();
}
However, when trying to connect to the databse using Laravel, the application throws me the PDOException error.
Appreciate any help on this. Thanks in advance!
The exception you get:
PDOException: Could not find driver
is given by PHP's PDO whenever the driver to your database could not be found. PDO needs a driver to operate with different databases (e.g. Sqlite, Mysql, ...). And PDO looks for the driver based on the DSN. In your case the DSN is:
sqlite:app/database/production.sqlite
And for the driver is looked only in the part before the first colon (":"):
sqlite
The string sqlite is used to find the sqlite3 driver (see PDO_SQLITE DSN in the PHP manual).
There is only a single place in all PDO where this exception is thrown (php 5.4 lxr) and it only gets thrown in case for the text before the colon in the DSN no driver could be found. This is also what you can expect from the error message.
As you've already done the checks outlined in the best answer to "How to determine if PDO is enabled in PHP" you are already certain that the PDO sqlite extension has been loaded.
Just to make this clear: The PHP extension which contains the PDO driver for sqlite is named pdo_sqlite which you have checked to be loaded.
The only explanation I have is that you did load the extension but PHP was not able to load the driver. According to PHP sources (php 5.4 lxr) this can have exactly two reasons:
The PDO driver requires a different PDO API version
PDO must be loaded before loading any PDO drivers
(technically there is a third reason but it should be ignored: adding the driver to the hashtable of PDO drivers failed, this is pretty internal and has nothing to do specifically with PDO)
As the extension is loaded, but the driver is not found, I suspect there was a problem registering the PDO driver. You should checkout the PHP error log for startup errors. As you say you have this problem on a shared hoster you need to contact the support where you find the PHP error log. You're looking for startup errors. Sometimes these error are also shown in the error log of the webserver depending on which PHP SAPI interface is used.
Please also provide the information from phpinfo() so that additional guidance can be given. With the information you've provided you can rest assured that the sqlite driver for PDO has not been loaded. This is a configuration issue.
Related
I have this error:
PHP Fatal error: Uncaught Error: Call to undefined function mysql_connect() in /home/epuedu/public_html/journal/epuojs/ojs/lib/pkp/lib/adodb/drivers/adodb-mysql.inc.php:456
After googleing this error on OJS: I found this answer:
If it is PHP 7 you may need to select the MySQLi driver rather than the MySQL driver.
So i understand that PHP7 don't use MYSQL driver any more.
My question: How can swithch OJS connetion to MYSQLi driver?
Thanks
I found that I can select the driver from the first page of installing OJS, after choosing User name, password, database details, you can chose MySqli as well.
I hope this answer help others like me.
Alternatively, if you have access to the config.inc.php go to the database section and update the driver to "mysqli", eg:
;;;;;;;;;;;;;;;;;;;;;
; Database Settings ;
;;;;;;;;;;;;;;;;;;;;;
[database]
driver = mysqli
I've been tasked with taking all of our MySQL databases and migrating them to SQL Server. In attempting to get PHP 5.3.24 to work with MSSQL, I've done the following:
Copied the non thread-safe drivers to /php/ext.
Updated my php.ini file to include the following two lines:
extension=php_pdo_sqlsrv_53_nts_vc9.dll;
extension=php_sqlsrv_53_nts_vc9.dll
Restarted IIS 7 running on Windows Server 2008 R2.
phpinfo shows sqlsrv under Registered PHP Streams, and sqlsrv also appears under PDO drivers and pdo_sqlsrv support shows as "enabled." Yet, when I try to connect via my application, I get the following:
Fatal error: Uncaught exception 'PDOException' with message 'could not find driver' in C:\inetpub\wwwroot\mystuff\myphpconnectfile.php
My connect string looks like this:
$con = new PDO("mssql:host=xxx.xxx.xxx.xxx,1433;dbname=mydb", "user", "pwd");
$con -> setAttribute(PDO::ATTR_ERRMODE, PDO::ERRMODE_EXCEPTION);
return($con);
Looks like it's finding the server okay, but not the PHP/PDO mssql drivers. What have I missed?
EDIT: Configure Command under phpinfo shows the lines "--without-mssql" "--without-pdo-mssql". I don't know where to go to change this, or if it's necessary.
You're using an invalid DSN connection string for MSSQL. You need to use the format found here.
new PDO('sqlsrv:Server=xxx.xxx.xxx.xxx,1433;Database=mydb', 'user', 'pwd');
In PHP scripts, it looks like this is how you connect to an odbc database:
$connection = odbc_connect("Driver={SQL Server Native Client 10.0};Server=$server;Database=$database;", $user, $password);
The problem I'm having is that I don't know what to use for "Driver=". What I put in there is what was provided for another script I saw. In my script, all I do is try to connect using this line, but I get the following error:
Warning: odbc_connect(): SQL error: [unixODBC][Driver Manager]Data source name not found, and no default driver specified, SQL state IM002 in SQLConnect in /srv/www/htdocs/site/test.php on line 8
From what I can tell, it looks like the driver I specified is incorrect. The database I am trying to connect to is an MSSQL database, and I only plan to query for information from it. Is there a way to list the database drivers I have available on my system? I've never had to install/configure any drivers like this before (I've never done anything like this; all php work I've done in the past has been with MySQL). Also, I don't want to compile other software onto my system (if possible); I would prefer to install all packages from repos.
You should have a file called odbcinst.ini (probably in /etc or /usr/local/etc but you can locate it with the command odbcinst -j). This file defines your ODBC drivers. Each driver is named within the [] in each section.
You might find Linux ODBC useful as it contains a thorough explanation of unixODBC, how it works and how to define data sources.
The question was how to find the list of ODBC drivers available. In the command line run:
odbcinst -q -d
This will list the drivers if you don't know already.
I inherited an old Cakephp site that was using adodb as a driver to connect to an MSSQL database and it turns out this is no longer supported in the new version of cake (1.3, we are in 1.2) so I'm trying to change the driver so I can upgrade. We're using IIS and a sql server 2005 database on a different server, php 5.2.17. However using driver "mssql" gives me the following errors:
PHP SQL Server interface is not installed. For troubleshooting information, see http://php.net/mssql/
Call to undefined function mssql_min_message_severity()
The top error leads me to a page regarding the old php_mssql.dll, which according to this question: ( CakePHP: error when trying to use mssql datasource ) will become a problem when I switch to PHP 5.3 so I'm trying to use the php_sqlsrv*.dll for my php version but I still get the error. Could never get the mssql.dll one to work either. I do however see "sqlsrv support enable" in phpinfo.php and the whole sqlsrv section is intact there.
In cake php I'm using "driver => 'mssql'", is this the correct driver for the new sqlsrv dll? Is there something I'm missing? For kicks I tried 'driver' => 'sqlsrv', that fixes the php SQL Server interface error but I still get
"Fatal error: Call to undefined function sqlsrv_min_message_severity() in C:\Inetpub\wwwroot\riverstone-dev\www\cake\libs\model\datasources\dbo\dbo_sqlsrv.php on line 107"
Installing the latest SQL Native Client set from Microsoft and reenabling the extension in PHP has worked, albeit on a different server. Please try the drivers below if having a similar problem:
http://www.microsoft.com/download/en/details.aspx?id=20098
I am trying to connect to MS SQL database in Doctrine 2.0, but I get this error all the time: Fatal error: Uncaught exception 'PDOException' with message 'could not find driver'.
I have already found that I need to install PDO SqlSrv extension to my local PHP (using Wamp), so I have done it (copied dlls into ext folder, edited php.ini, restarted), but the problem is still the same. I am trying to use some drivers I have downloaded, name of the file is SQLSRV20.EXE. In Doctrine config I have this as a driver: pdo_sqlsrv.
Has anybody same experience or is here just somebody who knows what have I to do to make it work?
I had a heck of a job trying to get PDO driver's working - it turned out i just needed to reboot my system.
..this shouldn't have been necessary but it did work. So if you are sure you have taken all the steps necessary to enable the drivers and it's still not working, give the reboot a shot.