I use PhpStorm to create a web page that saves data to a SQLite database. I have created tables in the DB, installed drivers in PhpStorm and it says, the connection is successful.
Ok, but when I try to open it in Chrome, it says:
Fatal error: Uncaught PDOException: could not find driver in C:\Users\maness\PhpstormProjects\icd0007\index.php:4 Stack trace: #0 C:\Users\maness\PhpstormProjects\icd0007\index.php(4): PDO->__construct('jdbc:sqlite:db1...') #1 {main} thrown in C:\Users\maness\PhpstormProjects\icd0007\index.php on line 4`
The code on line 4 within the index.php file is the following:
$connection = new PDO('jdbc:sqlite:db1.sqlite');
I have turned on every SQL extension in php.ini, tried different options - no result. Can you name the exact extensions needed to launch SQLite, or what am I doing wrong?
P.S.
PhpStorm SQLite Xerial drivers. I use PHP from XAMPP folder.
jdbc is not a valid PDO driver.
Since you want to connect to a SQLite database, remove jdbc from your dsn:
$connection = new PDO('sqlite:db1.sqlite');
You seem to have confused PhpStorm's SQLite connectivity with PHP's.
Related
I've been given access to an Oracle Server via ODBC and tested the connection using Oracle SQL Developer. These are the connection constants I've set in PHP:
define('APP_DB_HOST', '192.168.1.1');
define('APP_DB_PORT', '1521');
define('APP_DB_USER', 'MyUser');
define('APP_DB_PASS', 'MyPass');
define('APP_DB_SID', 'MyDatabaseSID');
define('APP_DB_SCHEMA', 'MyDatabaseSchema');
With ADOdb/ODBC, I should be able to use the below, so that I don't need to involve a tnsnames.ora entry:enter link description here
$dsn = '(DESCRIPTION=(ADDRESS=(PROTOCOL=TCP)(HOST='.APP_DB_HOST.')(PORT='.APP_DB_PORT.'))(CONNECT_DATA=(SERVICE_NAME='.APP_DB_SID.')));User Id='.APP_DB_USER.';Password='.APP_DB_PASS.';';
$db->PConnect($dsn, APP_DB_USER, APP_DB_PASS, APP_DB_SCHEMA);
I get the ADOdb Warning:
Warning: odbc_connect(): SQL error: [unixODBC][Driver Manager]Data source name not found, and no default driver specified, SQL state IM002 in SQLConnect in [..]/adodb/drivers/adodb-odbc_oracle.inc.php on line 87
Have others done this before, and if so, how so?
Beyond ADOdb, if anybody has a less complicated method of connecting by ODBC to Oracle with PHP7.4+, please do share.
I would also suggest you to move to the OCI8 native driver if you have a bit of time and not too much refactoring to do.
Your server should already have an Oracle client installed (to make the current TNS and ODBC work), so the only thing to do is to install the OCI8 Oracle DDL PHP extension. Just copy it to php/ext/ and load it in your php.ini
In the meantime, you can test if the following code works:
require_once("include/adodb5/adodb.inc.php"); //depends on your adodb folder
$conn = NewADOConnection("oci8");
$conn->connect(APP_DB_HOST, APP_DB_USER, APP_DB_PASS, APP_DB_SID);
For info, you can check if your system admin has already installed the OCI8 extension by looking for the OCI8 section in the PHPINFO :
If that is an option for you, I would strongly recommend to connect using the native oci8 driver, instead of relying on ODBC. Refer to ADOdb documentation for connection examples.
If you're stuck with ODBC, then I believe you need to adjust your DSN to specify the name of the driver you want to use in the connection string, e.g. Oracle in instantclient_19_6
Driver={OdbcDriverName};Server=(DESCRIPTION=(ADDRESS=(PROTOCOL=TCP)(HOST=xxx)(PORT=xxx))(CONNECT_DATA=(SERVICE_NAME=xxx)))
In my opinion it's better to specify the user id and password in the function call, i.e. $db->connect($dsn, $username, $password), but if you must have it in the connection string, you may want to try it with uid=xxx;pwd=xxx instead of User Id=xxx;Password=xxx
As an alternative, you could also create a System DSN in your ODBC configuration, and just refer to it by name, instead of hardcoding the TNS connection string directly in your code.
See also Create a DSN for the function odbc_connect for Oracle.
Trying to get it to connect in this environment:
Windows 7 Pro - 64bit
MS Access 2010 - 32bit (Tried both ACCDB and MDB versions)
ADODB abstraction package, Version 5.20.9
This is the test code:
include("C:\php\adodb5\adodb.inc.php"); // includes the adodb library
$db = NewADOConnection("access"); // A new connection
$db->Connect("", "", "", "D:\...\PhpPlay.accdb");
I've tried all kinds of variations for host, user and password params in the $db-> connect line, but no success. (The first two lines execute without error.) Here's the error message for line 3:
PHP Warning: odbc_connect(): SQL error: [Microsoft][ODBC Driver Manager] Data source name not found and no default driver specified, SQL state IM002 in SQLConnect in C:\php\adodb5\drivers\adodb-odbc.inc.php on line 66
So I'm grasping at straws now. I'm concerned about the mixed 32/64 bit settings, but don't want to do something drastic unless someone can confirm that this is a problem.
Thank you for any ideas you might be able to provide!
Third party modules are not needed. Simply use PHP's PDO class and the already installed MS Access ODBC driver:
DSN Version
$database="D:\...\PhpPlay.accdb";
$db = new PDO("odbc:DSN=MS Access Database;DBq=$database;");
Driver Version
$database="D:\...\PhpPlay.accdb";
$db = new PDO("odbc:Driver={Microsoft Access Driver (*.mdb, *.accdb)};DBq=$database;");
I am developing a website. I need to use PDO. I ran phpinfo(); and it said:
PDO Driver for SQLite 3.x enabled
SQLite Library 3.8.10.2
Although writing
$pdo = new PDO("path/to/db.db");
Gives me error if as this function doesn't exist.
Uncaught exception 'PDOException' with message 'could not find driver`.
Am I doing something wrong? (also that db file is sqlite 3 format). Any advice? Thanks ! (btw my website is made with wordpress)
It should be $pdo = new PDO("sqlite:path/to/db.sqlite");
2nd result from Google http://henryranch.net/software/ease-into-sqlite-3-with-php-and-pdo/
UPDATED
My latest code as follows:
$file ="sqlite:C:\New folder\\test.db";
echo $file;
$handle = new PDO($file) or die("Could not open database");
Error
sqlite:C:\New folder est.db
Fatal error: Uncaught exception 'PDOException' with message 'could not find driver' in C:\inetpub\wwwroot\NetBeans\PHP&SQLITE.php:20 Stack trace: #0 C:\inetpub\wwwroot\NetBeans\PHP&SQLITE.php(20): PDO->__construct('sqlite:C:\New f...') #1 {main} thrown in C:\inetpub\wwwroot\NetBeans\PHP&SQLITE.php on line 20
I'm trying to use PDO driver however the error keep prompting me saying cant find the driver when it's in my extension php folder. I'm at my wits now.
I'm using SQLITE version 3 and PHP version 5.4.3.
I already placed the database file inside my r/w folder but it Fatal error: Call to undefined function sqlite_open(). I already researched on the web for alot of sources but the my directory path still returns some strange error (Sorry if i'm too noob, first time learning).
My code as follows:
$db ="C:\New folder\test.db";
Test to print my directory path of the database.
echo $db;
$handle = sqlite_open($db); //or die("Could not open database");
Debug result
C:\New folder est.db
Fatal error: Call to undefined function sqlite_open() in C:\inetpub\wwwroot\NetBeans\PHP&SQLITE.php on line 18 which is "$handle = sqlite_open($db); //or die("Could not open database");"
Kindly advise where did I do wrong? The path I specified was correct but when I print out, it shows wrong path.
Thanks
one problem you have is that you are escaping (inadvertently) some of your path characters.
As your var_dump shows.
C:\New folder est.db
change your $db variable definition to
$db ="C:\New folder\\test.db";
or just put path in single quotes so PHP won't try and parse the string
$db ='C:\New folder\test.db';
and believe it or not in most cases unix paths will work:
$db ="C:/New folder/test.db";
as for the remainder of your problem, you need to make sure you have sqlite 2 enabled. View your php info and check to see if you a section like:
SQLite
SQLite support enabled
PECL Module version 2.0-dev $Id: sqlite.c 306939 2011-01-01 02:19:59Z felipe $
SQLite Library 2.8.17
SQLite Encoding iso8859
if not, in your php.ini make sure the line
extension=php_sqlite.dll
is uncommented and present (and the .dll exists in your extension folder).
However most people will recommend that you use the PDO driver for sqlite (and for any other database) as it will provide a more consistent paradigm across the different databases (you can use the same code with most databases).
[edit]
I found some comments in the php manual that may shed some light on your issues.
It seems that the directory that contains your sqlite database must be
writeable by the web server. Making just the file writeable won't
work.
and
Don't forget "extension=php_pdo_sqlite.dll" has to be enabled in
php.ini (if you use xampp is will be disabled by default) .
I've decided to switch from MySQL to PostgreSQL recently, mostly just to learn a new DB. It's been pretty painful, but I think I'm close.
I'm using php and PDO, my PDO driver has been successfully install and configured.
Opening my site, I get the error:
Connection failed: SQLSTATE[08006] [7] FATAL: Ident authentication failed for user "postgres"
I'm using the following connection calls (I've tried a few variations of calling user/pw in the $dsn variable, and in separate $user/$pass variables, and including port=5432):
$dsn = 'pgsql:dbname=db1;host=localhost;user=postgres;password=pass';
$db = new PDO($dsn);
Also, I'm able to log into my db from the command line:
$ su postgres
(pass)
$ psql db1
output:
could not change directory to "/home/ec2-user" psql (8.4.9) Type
"help" for help.
db1=#
Any ideas? I'd love to provide more info if needed.
Is your pg_hba.conf file all right? It's a known source of pain at the beginning w/ PostgreSQL. And, the situation you mention, is a good candidate for such kind of a problem. :-)