Home > Article > Backend Development > Solution to PHP Fatal error: Class ‘SQLiteDatabase’ not found
When we develop using PHP, we sometimes encounter an error message: PHP Fatal error: Class ‘SQLiteDatabase’ not found. This error occurs because PHP does not enable the SQLite extension by default.
So, if we want to use SQLite database when developing with PHP, how to solve this error? Next, this article will introduce several different solutions for you to better understand and apply.
Method 1. Turn on the SQLite extension
PHP does not turn on the SQLite extension by default, so we need to manually turn on the SQLite extension when developing using PHP. The specific steps are as follows:
sudo nano /etc/php.ini
If you are running on a Windows system, you can find the PHP installation directory in the file browser php.ini file and open it.
;extension=sqlite3 ;extension=pdo_sqlite
Remove the preceding semicolon.
Method 2. Install the SQLite extension
If you still get the same error after turning on the SQLite extension, it means that the extension is not installed correctly. You can try to use the following command on Linux Installation on the system:
sudo apt-get install php7.0-sqlite3
If you are running on a Windows system, you can download the relevant SQLite extension from the PHP official website and then install it manually.
Method 3. Use PDO extension to connect to SQLite database
PDO is an extension of PHP and shows good versatility in connecting different databases. We can connect to SQLite database using PDO extension.
The following is a sample code, you can modify it according to your specific situation:
try { $pdo = new PDO("sqlite:/path/to/database.sqlite"); // 连接 SQLite 数据库 } catch(PDOException $e) { echo 'Connection failed: ' . $e->getMessage(); }
Finally, when you successfully solve this problem, you can learn about using SQLite database by the way Knowledge, using SQLite database in PHP can realize lightweight database operations, and can run on various operating systems, while supporting concurrent access by multiple users, which is simple and efficient.
The above is the detailed content of Solution to PHP Fatal error: Class ‘SQLiteDatabase’ not found. For more information, please follow other related articles on the PHP Chinese website!