I am trying to import an SQLite file in my Laravel project which I am importing and storing at runtime. When I try, I find that sometimes it works and other times it does not. Here is the code that I am using to generate the PDO connection:
try{
$db = new PDO('sqlite:'.$dbSavedLocation);
return $db;
}
catch(\PDOException $e){
LogRepo::logError(0, $e->getMessage(), 1, $e->getFile(), $e->getLine());
return null;
}
"SMS Database process error: SQLSTATE[HY000] [14] unable to open database file" when trying to open the file?
Why would this not work? What would cause the error of
Is the .sqlite file opened by any other programs?
I've had it happen a few times where I've had it open in SQLiteBrowser and gotten a similar error, but having it open elsewhere will prevent Laravel from being able to open the database.
Related
A bit about my current setup, The website is hosted on a windows server 2012 IIS with PHP 7.1, the site runs using Laravel with Medoo to load the database, however on any form of SQL statement the code fails with the error mentioned in the title.
Currently the file permissions are on Full Control for debug purposes
The code used for the call is the following
$pdo = new \Medoo\Medoo([
'database_type' => 'sqlite',
'database_file' => $config->database_path
]);
$query = $pdo->select('computers', '*');
I have tried making a SQL dump of the SQLite database file using a program called "DB Browser for SQLite" and the making a new database file from scatch then importing the SQL dump.
When this is done the program works without problem, so my current thought is there might be a limit on PDO SQLite file limit size since the original file is about 2.8MB while the new is 1.9MB
Is there anyone who have encounter a similar problem? or have any advice on how to fix the current problem?
I am trying to implement an PHPUnit integration-test for a Controller. Within the controller I instantiate an Object of the PHPRedis-class (https://github.com/phpredis/phpredis#usage):
//connect to redis database
try
{
$this->objPHPRedis = new \Redis();
$this->objPHPRedis->connect('127.0.0.1');
}
catch(\RedisException $e)
{
$this->log($e, 1);
}
catch (\Exception $e)
{
$this->log($e, 1);
}
This works great when I process normal requests, but it fails when I execute the test:
PHP Fatal error: Class Redis not found in /var/www/.../MyController.php on line 100.
I have no idea where to start searching for the problem. Does anybody have an idea what the problem could be?
Your CLI config for php has the redis module not loaded. Find your CLI php.ini, probably named cli_php.ini or something similar and make sure your redis module is loaded there as well.
I'm stuck with this problem. I'm trying to access an sqlite database from a different location. So far I have tried using PDO to access such file. I've tried using PDO since from what I read here on SO that would be easier. I only want to do some select queries on the database.
try{
$DBH = new PDO("sqlite:192.168.48.52/data/log/localdb.db");
echo "connected";
}
catch(PDOException $e) {
echo $e->getMessage();
}
it outputs an error message saying 'SQLSTATE[HY000] [14] unable to open database file'. I could access the location via SSH/putty or manually input the directory through a web browser. But not through PHP coded location. The file resides actually in a gsm gateway interface which has a -rw-r--r-- permission.
If I were to actually download the file and put it in my htdocs folder it does open the file and echos 'connected'
$DBH = new PDO("sqlite:localdb.db"); <--- **like this**
I also tried doing this since it requires some authentication to access the directory.
$DBH = new PDO("sqlite:admin:admin#192.168.48.52/data/log/localdb.db");
to no avail.
Thanks in advance.
i think you miss 1 colon after the IP :
$DBH = new PDO("sqlite:admin:admin#192.168.48.52:/data/log/localdb.db");
I've spent many-a hour trying to get a local webserver working (I'm new)
I created a sqlite3 database ('database.sql') in the www folder, and tried calling it with numerous different php commands (php 5.5, I checked) such as '$test = new SQLite('database.sql')' or the same with SQLite3, both with no luck. Also tried $test->open('database.sql').
Always with the fatal error "Class 'SQLite' not found". I've spent too many hours on what I'm sure is a very simple problem, I'm sorry to have to ask this!
To open a DB using PHP5 and SQLite we need to use a PDO and not the sqlite_open() function.
This is how to open or create a database: (not sure if it's bug free)
try {
/*** connect to SQLite database ***/
$dbh = new PDO("sqlite:VPN0.sqlite");
echo "Handle has been created ...... <br>";
}
catch(PDOException $e) {
echo $e->getMessage();
echo "<br>Database is loaded UNSUCCESSFULLY .. ";
die("<br>Query is closed $error");
}
echo "Database loaded SUCCESSFULLY ....";
Hope this helps!
There is a php package called sqlite3 which you can use (as well as PDO which is given above). Here is a fraction of code which uses it.
$db = new SQLite3(DATABASE);
if (isset($dbversion)) { //only newer versions of chat will have this
$version = $db->querySingle("SELECT value FROM parameters WHERE name = 'db_version'");
Where the DATABASE variable has been defined with
define('DATA_DIR',$datadir); //Should be outside of web space
define('DATABASE',DATA_DIR.'chat.db');
Are you sure that the package is installed on your server?
If you're still having problems you can do a couple of things. First, use phpinfo(); in a page to determine if the SQLite3 extension is installed.
Second, if you want to use PDO make sure that the following line in your php.ini is un-commented:
extension=php_pdo_sqlite.dll
If you have to un-comment this you will need to restart your server for the changes to take effect.
I'm trying to use php for a class project, and I'm getting this error when I try to create a database connection. My connection code is as follows:
try {
$con = new PDO('mysql:host=nova.umuc.edu;dbname=cs495', $user, $pass);
//check connection
}
catch (PDOException $e){
echo "Error!: " . $e->getMessage() . "<br/>";
die();
}
A little bit of googling, and this seems to be because the driver isn't loaded in the configuration file (php.ini). I've looked at the php_info, and while the configuration file path is listed, it says no configuration file is loaded. The PHP version is 5.2.13.
I've even gone to this directory on the server, and inside of that directory is a readme file that says this directory is depreciated for php's configuration file! Is this something I can workaround, or does the server configuration have to change?