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/
Related
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.
In first point. I am absolutely a noob in PHP and PEAR. For exercising I have worked with PHP, Pear and Mondial DB of Oracle offline, but now I wanted to connect to my Database on 1and1.com.
Following I have tried:
$dsn = 'mysql://dbo5235xxxxx#10.24.xxx/db5235xxxxx'; //Have it tried with password too and many other variations
$sql = "SELECT * FROM Vereine";
$db = MDB2_Util::connect($dsn);
If I upload this file on my webserver and when I try to call this page, I get an error.
Fehler beim Verbindungsaufbau mit [mysql://dbo5235xxxxx#10.24.xxx/db5235xxxxx] : MDB2 Error: not found
The error Message:
"Fehler beim Verbindungsaubau" is an own deinied Message in MDB2_Util.
If I try to connect with MDB2::connect, then the Message calls only:
MDB2 Error: not found
What can be the Error? Why it doesnt show the real Error or a helpful hint. Can I debug? If yes, how?
Best Regards Benny
This can occur even if you have installed an MDB2 driver, but PHP can't find or can't read it.
As a practical example, I experienced this problem on a system on which the UMASK value had been changed from 022 to 027. Even though the MDB2 driver had been installed (with root privileges), the user under whom php-fpm was running lacked access to the library's files.
I've installed Propel correctly according the installation manual (http://propelorm.org/documentation/01-installation.html). I checked that PHP was loading pdo_mysql driver so I made a phpinfo() test and It showed that everything was correct. Nevertheless, when I made a simple Query using Propel, as showing below:
<?php
//define('BASE_PATH', '/Users/jvarela/Development/Crack/Crack-Server');
define('BASE_PATH', '/Library/WebServer/Documents');
ini_set('include_path', BASE_PATH.':'.ini_get('include_path').':'.BASE_PATH.'/propel/vendor/propel/src');
spl_autoload_extensions(".php"); // comma-separated list
spl_autoload_register();
// setup the autoloading
require_once 'propel/vendor/autoload.php';
// setup Propel
require_once 'propel/vendor/generated-conf/config.php';
echo 'All ok, for now...';
$a = new JugadorQuery();
$a->findPK(1);
?>
I'm receiving the error below.
Fatal error: Uncaught exception 'PDOException' with message 'could not find driver' in /Library/WebServer/Documents/propel/vendor/propel/src/propel/runtime/connection/connectionfactory.php on line 44
( ! ) PDOException: could not find driver in /Library/WebServer/Documents/propel/vendor/propel/src/propel/runtime/connection/pdoconnection.php on line 50
The strange thing is that if I just create a PDO object like the example below, I get no error and It connects to the Database properly
$test = new PDO("mysql:host=localhost","user","pass")
Have anyone got the same error or known if I made a mistake installing Propel v2.0 properly? Thank you
PD: I'm using Apache v2.2, PHP v5.4 and MySQL v 5.6
Regards.
I am completely new to php and wish to read data from a sqlite database.
I have got the hello world to work correctly but the following two scripts failed to execute without an error:
<?php echo sqlite_libversion(); ?>
<?php print_r(SQLite3::version()); ?>
The first script gives the error:
Fatal error: Call to undefined function sqlite_libversion()
The server on which I have my website has the following php configuration.
http://php.binerorockar.se/
where it shows:
pdo_sqlite: PDO Driver for SQLite 3.x enabled
Do I have sqlite3 support? How can I test this support?
There are several ways to access a SQLite from PHP. In your examples, you are using the SQLite and SQLite3 extensions for PHP. But you have neither of these extensions actually installed in your PHP system.
You do have the SQLite driver for PDO installed. This is the generic API for SQLite and other databases. The syntax would look like this to get the SQLite software version.
// connect to in-memory SQLite database
$db = new PDO("sqlite::memory");
echo $db->query("SELECT sqlite_version()")->fetchColumn();
To use the SQLite specific API functions, need to uncomment extension=sqlite.so in the PHP config file.
I have used php5 to create a sqlite database. The database works fine when accessing its data using php.
However when I try and connect to the same sqlite file using firefox sqlite manager, I get the following error....
SQLiteManager: Error in opening file jTest.sqlite - either the file is
encrypted or corrupt Exception Name: NS_ERROR_FILE_CORRUPTED Exception
Message: Component returned failure code: 0x8052000b
(NS_ERROR_FILE_CORRUPTED) [mozIStorageService.openUnsharedDatabase]
My question:
Can you use php to create sqlite databases and have them work in other applications?
regards J