I have read a good bit on Stackoverflow, PHP Doc's, etc. So far nothing helps me open my SQLite3 database in PHP 5.6. This is my code snippet:
$db_file = "D:/Websites/Intranet/InetPub/wwwroot/WebDB/HamLog - SQLite/HamLog.SQLite";
// open database file
//$handle = sqlite_open($db) or die("Could not open database");
//$db = new sqlite($db_file) or die("Could not open Dan's HamLog.SQLite");
//$db = new Database($db_file);
$this->db = new PDO("sqlite:.$db_file", NULL, NULL);
//$this->db = new SQLite3($db_file);
You can see I've tried a number of things that all just died at the open attempt line with an error code. The active try at least gives an error saying it is unable to open the database. I can open the database using the sqlite console. Apparently in recent PHP releases, SQLite has been relegated to obscurity, by old references in the PHP documentation. The best I've found is the SQLite library is now housed in PECL. But then I read that its best to install PECL through PEAR. At this point I need some help. How do I open my SQLite database named: HamLog.SQLite in PHP?
Related
Good day everyone, i have an application that uses .dbf files to store data and i would like to run some queries on those files. the problem is that i don't know how .. i've spoken with the people from support about it and they told me that i can an ODBC driver or the dedicated one for visual foxpro Ole DB. I found something called dabse in php manual yet on php 5.3 it doesn't support it or i didn't install it right because it didn't work, from what i've read on google seems that it supports until php 5.2 or something like that.
Can you help me figure it how to do it ? i've googled around but couldn't find anything that might help me out.
Edit
$excelFile = realpath('C:\\db\\article.dbf');
$excelDir = dirname($excelFile);
$dsn = "DRIVER={Microsoft dBase Driver (*.dbf)};SourceType=DBF;SourceDB=C:\\db\\article.dbf;DefaultDir=$excelDir;Exclusive=NO;collate=Machine;NULL=NO;DELETED=NO;BACKGROUNDFETCH=NO;";
$conn=odbc_connect($dsn,"","");
$sql = "SELECT * FROM articole.dbf";
$result = odbc_exec($conn, $sql);
The Error:
Warning: odbc_exec() [function.odbc-exec]: SQL error: [Microsoft][ODBC dBase Driver] External table is not in the expected format., SQL state S1000 in SQLExecDirect in E:\public_html\odbc\index.php on line 7
Do you have SQL Server? You could create a linked server to the DBF files. Check out this link:
Linked Server
See also these links for querying DBase or Foxpro tables with ODBC or OLE DB:
Dbase ODBC
Foxpro OleDB
Having a hard time to figure out the path to set for my sqlite3 database using PDO in PHP.
My code as follows:
$handle = new PDO('sqlite:/C:/New folder/sqlite/test.db') or die("Could not open
database");
echo $handle;
$query = "SELECT * FROM student";
Debugging result:
It returns a blank web page instead of printing out the $handle. I already set my desired path where my sqlite database file was stored. What did i miss out ?
Kindly advise.
Firstly you need to know what PDO drivers are installed, make a blank file with in it:
<?php phpinfo(); ?>
Then look for the PDO section and you should see somthing along the lines of:
PDO drivers mysql, sqlite, sqlite2
If you only have mysql then you need to install the sqlite pdo driver. Use google for that, dont forget also check your production server too, else your create something you possibly cant use on your hosting.
As the PDO driver is much like the old sqlite_open() it will create the database file for you if its not found.
also as you may be aware spaces in file paths are not so good and can cause problems,
Instead of using:
sqlite:/C:/New folder/sqlite/test.db you should at least rename your New Folder to somthing else: sqlite:/New_folder/sqlite/test.db
I'm trying to use the dbase library in php5.3 to open a .dbf file. I've got the dbase.so library installed and active on my php5 build and I'm executing the following code:
$db = dbase_open('CMX.dbf', 0);
if( $db ){
echo 'success';
dbase_close($db);
}
Where CMX.dbf is a Visual FoxPro9 data table and is located in the same directory as the executing script with read/write/execute permissions enabled.
The following is an exert from /var/log/apache2/error.log:
PHP Warning: dbase_open(): unable to open database CMX.dbf in /var/www/test.php on
line 28
As this error/warning is not very descriptive, I'm having issues tracking down the root cause. Can anyone help with this?
Not positive about PHP, nor Apache, but typically, when trying to connect to database files (or Foxpro), the typical approach would be to have a CONNECTION to a PATH, then perform a query against the name of the table....
Try this (in foxpro):
use cmx.dbf
copy to cmx_php.dbf type fox2x
I was having a similar problem where some dbs would open and others would not. This allowed me to access the db with php/dbase.so
I found the info here in the comments section.
Try this:
$db_path = "CMX.dbf";
$db = dbase_open($db_path, 0) // 0=ReadOnly, 1=WriteOnly 2=ReadWrite
or die("Error! Could not open dbase database file '$db_path'.");
if( $db ){
echo 'success';
dbase_close($db);
}
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. :-)
I have an EC2 instance running a WordPress site. The WordPress db is on a RDS instance. I want to connect to the db over SSL.
From what I've read, the MySQL extension that WordPress uses out of the box doesn't support SSL. So, I've installed a WordPress db script that uses MySQLi, which does support SSL.
The problem I encountered is that Amazon only supplies one key file (more info), and all the examples I can find using MySQLi over SSL include at least 3 files:
$db = mysqli_init();
$db->ssl_set('server-key.pem','server-cert.pem','cacert.pem',NULL,NULL);
I'm able to connect to my db over SSL from the mysql command line app. Can anyone tell me what I need to do to get PHP's MySQLi extension to work, given that I only have the 1 file?
Turns out this was less complicated than I thought. Turning up the error reporting level uncovered an error in my code that I hadn't caught. Using ssl_set this way works:
$db = mysqli_init();
$db->ssl_set(NULL,NULL,'/path/to/mysql-ssl-ca-cert.pem',NULL,NULL);
$db->real_connect($dbhost,$dbuser,$dbpassword,$dbname);
Try this:
$db = mysqli_init();
$db->ssl_set(null, 'https://rds.amazonaws.com/doc/mysql-ssl-ca-cert.pem', null, null, null);