Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Fastest way to test a server for sqlite via a PHP file?

Tags:

php

sqlite

I'm not sure if my server has sqlite on it, so I want to use a PDO object to test and see if the server supports sqlite. I tried:

<?php
echo `sqlite3 -v`;

got the following error: Warning: shell_exec() has been disabled for security reasons

like image 847
Wolfpack'08 Avatar asked Dec 02 '22 21:12

Wolfpack'08


2 Answers

You could just use function_exists() to check if sqlite functions are present, like this:

if (function_exists('sqlite_open')) {
   echo 'Sqlite PHP extension loaded';
} 

For SQLite3 the former won't work, so use this instead (courtesy of Prid's comment):

if (class_exists('SQLite3')) {
   echo 'SQLite3 extension loaded';
}
like image 157
Nelson Avatar answered Jan 07 '23 16:01

Nelson


Or you can simply use :

if (extension_loaded('sqlite3')) {
    // Do things
}

http://php.net/manual/en/function.extension-loaded.php

like image 21
Epoc Avatar answered Jan 07 '23 16:01

Epoc