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
Related
i must connect to sqlite db file using doctrine,
when i copy db file to php(composer) project i can easily connect to DB,
but when i try to make absolute path it says SQLSTATE[HY000] [14] unable to open database file
i'm using symfony4.2 project for it and doctrine2.5
my .env is like this
DATABASE_WSW="sqlite:////C:\\Program Files\\programX\\db.sqlite" or
DATABASE_WSW="sqlite:////C:\Program Files\programX\db.sqlite" or
DATABASE_WSW="sqlite:////C:/Program Files/programX/db.sqlite"
above examples don't work
when used like this works:
DATABASE_WSW=sqlite:///db.sqlite
what I'm doing wrong?
In my project I want to create console commands for dropping and creating DB, just like in Symfony2 like database creation command in laravel console? The way described in the answer to that question works fine for dropping DB, but when I try to create it with this code:
$dbType = \Config::get('database.default');
$dbName = \Config::get('database.connections')[$dbType]['database'];
\DB::statement("CREATE DATABASE `$dbName`");
I get an exception: SQLSTATE[42000] [1049] Unknown database 'my_awesome_db_name'. Any ideas?
Laravel is trying to connect to MySQL and select the database my_awesome_db_name. This isn't possible, because that database name doesn't exist yet (you haven't created it), so MySQL fails on the internal USE my_awesome_db_name command.
I have a database file on my computer called testing.sqlite, which contains a copy of me database that I want to use for testing (rather than connecting to my ordinary MySQL production server).
I created an entry in the config/database file in laravel as instructed, setting it to access the sqlite file, and it all look right. But when I try and actually do anything, I get the error message:
[Illuminate\Database\QueryException]
SQLSTATE[HY000]: General error: 26 file is encrypted or is not a database (SQL: select * from sqlite_master where type = 'table' and name = vendor_alerts)
I can access the file using sqlite testing.sqlite from the command line, why can't laravel read it?
The problem is that the version of sqlite is different. Laravel uses sqlite3, wheareas the sqlite command on your console might be an earlier version. Run sqlite -version from the command line to check your version - is is probably 2 something. You need to install sqlite3, and you'll find that it is not compatible - i.e. sqlite3 testing.sqlite will produce the same error you are getting from laravel.
So, upgrade your command line sqlite version, and copy the data into a new sqlite3 database, and laravel will work without trouble.
I am trying to use PHP's COM interface to query a database and create pivot tables from the data in an Excel Workbook.
I have configured the DCOM settings on the local machine to grant the user Local Access, Local Launch, and Local Activation privileges as well as Full Control of Configuration Permissions. I have also tried all three Identity settings.
Here is the code I am using:
<?php
$application = new COM("Excel.Application") or die("Unable to load Excel.");
$workbook = $application->Workbooks;
$workbook = $workbook->Add();
$sheet = $workbook->Worksheets(1);
$sheet->Activate();
$application->Quit();
?>
This is the error I am getting:
PHP Fatal error: Uncaught exception 'com_exception' with message 'Unable to lookup `Workbooks': Access is denied.
This is different than error I was getting before which told me that I didn't have access to the Excel COM object. Setting the permissions fixed that.
Environment is:
Windows Server 2012 R2
Excel 2010 (64-bit)
PHP 5.5.9 (64-bit)
I never was able to solve this, so we had to come up with a different solution and it actually is more stable and performs better. Hope it helps anyone else that may run into the same issue.
Our database is MySQL (but this should be possible with most databases), so we moved our query into its own script and used the mysql client to write the results directly to a file.
We then created an excel template with a data connection to the file and used the connection as the data source for the pivot tables.
Lastly we wrote a short vbscript to open the template, refresh the pivot tables, then and save the file as a new copy.
This had the added benefit of allowing us to make stylistic changes using Excel's interface, which was much faster than doing it programmatically.
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.