Home >Backend Development >PHP Problem >How to close php sqlite

How to close php sqlite

藏色散人
藏色散人Original
2021-07-19 10:20:592927browse

php SQLite closing method: 1. Create a database; 2. Create a new table named mytable; 3. Insert data into mytable; 4. Close newdb through "sqlite_close($db);" Database is enough.

How to close php sqlite

The operating environment of this article: windows7 system, PHP7.1 version, DELL G3 computer

How to close php sqlite?

SQLite database configuration

After the SQLite database is installed, we only need to cancel the ; in front of ;extension=php_pdo_sqlite.dll in php.ini.

1. Open php.ini

2. Enable extension=php_sqlite.dll extension (if you need to support PDO connection, you also need to enable extension=php_pdo_sqlite.dll extension)

3. Restart the Apache server

Commonly used functions in sqlite

Open or create database operations: sqlite_open(string name of the target database [, int operates the read-write mode of the database, string returns the database Error message]); //When using this method, if the database specified in the first parameter already exists, the connection will be made. If it does not exist, it will be automatically created; the read-write mode of the second parameter defaults to 0666.

Execute SQL statement operation: sqlite_query(resource database connection handle, string SQL statement);//Similar to the mysql_query() method in mysql.

The total number of records in the statistical table: sqlite_num_rows (resource the data set resource returned after executing the SQL statement);//Similar to the mysql_num_rows() method in mysql.

Data ID of the last operation: sqlite_last_insert_rowid (resource database connection handle);// Similar to the mysql_insert_id() method in mysql.

Returns the data set pointer of the query result: sqlite_fetch_array (resource database connection handle, resource data set resource returned after executing the SQL statement) is similar to mysql_fetch_array ( ) method.

SQLite database operation example

1. Create a database named newdb

$db=sqlite_open("newdb.db") or die('创建或连接数据库失败!');

2. Create a new table named mytable in the newdb database

sqlite_query($db,"CREATE TABLE mytable ( uid INT ( 11 ) NOT NULL PRIMARY KEY , uname VARCHAR ( 30 ) NOT NULL ) ") or die('新建表失败!');

3. Insert data into mytable

sqlite_query($db,"insert into mytable values (1,'Tom')") or die('添加数据失败!');

4. Take out all the data in the table and display it $val=sqlite_query($db,"select * from mytable");

while($ru=sqlite_fetch_array($val)){
print_r($ru);
}

5. Close the newdb database

sqlite_close($db);

SQLite has a database management tool similar to phpMyadmin

SQLiteManager manages the SQLite database

SQLite is a A lightweight file database, it complies with the ACID relational database management system. It takes up low resources, has strong scalability and strong compatibility.

The relationship between PHP and SQLite is like that between ASP and Access Relationship, Access is a file-type database, and SQLite is also a file-type database. The characteristic of a file-type database is that it does not require additional installation like databases such as Mysql, MSSQL, and Oracle. You only need to download before using a file-type database such as Access or SQLite. The corresponding extension driver package is then placed in the corresponding extension directory and can be used with a little configuration. Current PHP5 and above versions have built-in SQLite database extensions. You only need to enable the extension in php.ini to use it directly. For details, please refer to: SQLite database configuration in PHP5.

It is said that the source code package of SQLite has less than 30,000 lines of code, which adds up to less than 300KB. Its "lightweight" and "efficiency" can be imagined.

SQLiteManager and The difference between phpMyAdmin:

SQLiteManager will not automatically identify your database like phpMyAdmin. Before using SQLiteManager, you need to manually configure the path and name of the database. After configuration, you can manage it under SQLiteManager. Database.

SQLiteManager manages SQLite database operation process

1. Open the SQLiteManager that comes with the WAMP environment

2. Enter the name you want to manage in the name input box on the home page Database name (name of the database that has been created)

3. Click Browse, find the database file, and open it

4. Enter the absolute path of the database file in the path. Mine is in D: /www/mydb.db (Pay attention to the direction of the slash!)

5. Click Save

In this way, SQLiteManager can establish a connection with the newly created database. At this time, you can open the SQLiteManager Manage your SQLite database like phpMyAdmin.

Recommended learning: "PHP Video Tutorial"

The above is the detailed content of How to close php sqlite. For more information, please follow other related articles on the PHP Chinese website!

Statement:
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn