SQLite3 / PDO - No such table though it does exist - php

I have a problem with an SQLite3 database where I can access it either with the sqlite3 command or with the PHPStorm built-in database manager but the application I am working on doesn't find the tables in it. It correctly connects to the database it seems.
This line of PHP causes the PDOException:
$query = "SELECT * FROM users";
$results = self::$app->db->query($query);
And the exception is simply SQLSTATE[HY000]: General error: 1 no such table: users. I am using the Slim framework, by the way.
I don't really know what to do as I am new to Slim as well as SQLite.
Thank you for your help :-)

The database that you have opened does not contain this table.
SQLite will happily open any file name; if it does not exist, it will create a new, empty database.
Check your database file name.

Thanks to the accepted answer that pointed me in the right direction.
I am using Symfony 4.1 and realized that the base directory for Symfony is the public directory (should be app in 2.8) so to open my database I had to do :
# file: PROJECT_ROOT/.env
DATABASE_URL="sqlite:///../my_super.db"
But then, every call to doctrine in a command (like doctrine:schema:update) must be called in a direct subfolder of the project, like so:
PROJECT_ROOT/bin$ ./console doctrine:schema:update --dump-sql

Related

Database creation command in Laravel 5.1

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.

Multiple issues during Sylius installation

im trying to install Sylius with composer for an e commerce project however i just cant get it done..i follow the docs but i always get an other error when i fix one.
already fixed some errors eg. incl extension exception, paypal bundle renaming issues on git and memory size problem.
Now where im stuck:
When i fill the parameters with the interactive script
if i give any password for the database i get this:
Doctrine\DBAL\Driver\PDOException
Acces denied for user 'root'#localhost
if i dont give password then i get this:
Doctrine\DBAL\Driver\PDOException
SQLSTATE[HY000]Unknown database databasename_dev (it appends _dev prefix)
then in both cases it ends up with this: RunTimeException
An error occured when executing the ""cache:clear --no-warmup"" command
and the proccess is terminated with this exception..
i tried if i could continue with the $ cd acme
$ php app/console sylius:install commands but:
if i gave a password then get acces denied Doctrine\DBAL\Exception\ConnectionException
if didnt then Doctrine\DBAL\Driver\PDOException
SQLSTATE[HY000]Unknown database databasename_dev
i created the database manually which seems to solve the problem however get this: General error: 1007 cant create database databasename_dev; database exists
(i dont think this solution is the right one)
but after this it doesnt terminate yet and creates the database schema and then after some installation it terminates with this:
RuntimeException
The source file "C:\Users\user\acme\app/../web/bundles/cmfcreate/vendor/create/themes/midgard-tags/tags.css" does not exists
i checked the page if it may useable but got twig exception that currency not found and many components are missing from the page..
What's your workspace?
If you work on Windows with WAMP I'll give you some things to check :
set the database port to : 3306
create a new user for the database, juste for your sylius project
when you run create-project commande, in databaseport write : localhost
I hope it helps you.

Laravel sqlite saying the database is "encrypted or is not a database"

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.

reverse database won't work from terminal (PROPEL / BAKE CAKEPHP)

I've been trying to generate model classes from a local database using both propel and bake for cakephp , it seems that i have the same problem :
When I try to acces the database through bake or propel it gives me an error that it can't open the connection:
So I tried this :
I try to acces the database from the application using pdo it works just fine!!!
When I tried to acces database through terminal it's also working !!!
I really don't know what's the problem here !
You most likely have a separate php.ini config file for CLI and pdo_mysql is not loaded for CLI.

CDbCommand failed to execute the SQL statement when deploying to a server

I really don't know what causes this error.
CDbCommand failed to execute the SQL statement: CDbCommand failed to prepare the SQL statement: SQLSTATE[HY000]:
General error: 1 table 'YiiSession' already exists. The SQL statement executed was:
CREATE TABLE 'YiiSession' (
"id" CHAR(32) PRIMARY KEY,
"expire" integer,
"data" BLOB
)
Is it in the server or in yii..
but i guess it is in the yii part.
but what configurations did i miss?
i'm not really familiar with yii because im new to it.
any help please?
Thanks in advance
UPDATE: I check YiiSession in my database but it is not in there...
Delete the runtime folder.
Because runtime folder is used by the system for various tasks: session, logging etc.
It is also in the runtime folder that YiiSession table is created
In case anyone is still referencing this - the more complete answer is that Yii uses a SQLite3 database by default if you don't specify a connection string in your (CDbHttpSession) session config. This SQLite db is created in the runtime folder. (Which is why deleting the contents of the runtime folder works - you actually only need to delete the session-x.x.xx.db file.) If you want to use the same database you are using for your main connection, add:
'connectionID'=>'db',
to your session config. It's also recommended for production use you set autoCreateSessionTable to false, which will also prevent the error - you just need to make sure you deploy the SQLite db or set up the proper table in your main db. see here
By default, it will use an SQLite3 database named 'session-YiiVersion.db' under the application runtime directory. You can also specify connectionID so that it makes use of a DB application component to access database.

Categories