Home > Database > Mysql Tutorial > body text

UseSqliteinPython

WBOY
Release: 2016-06-07 15:22:50
Original
1066 people have browsed it

import sqlite3import os,sysDATABASE = os.path.dirname(__file__) + /sqlite.dbdef test_db():db = sqlite3.connect(DATABASE)cur = db.cursor()sql = create table post(ID INT PRIMARY KEY NOT NULL,TITLE CHAR(50),CONTENT TEXT,AUTHOR CHAR(30))data =

import sqlite3
import os,sys

DATABASE = os.path.dirname(__file__) + '/sqlite.db'

def test_db():
	db = sqlite3.connect(DATABASE)
	cur = db.cursor()
	sql = '''
	create table post(
	ID INT PRIMARY KEY NOT NULL,
	TITLE CHAR(50),
	CONTENT TEXT,
	AUTHOR CHAR(30)
	)	
	'''
	data = '''
	insert into post(id,title,content,author) values(1,'good news','you win the big prize','admin')
	'''
	print 'run the query'
	query = "select * from post"
	posts = cur.execute(query)
	for post in posts:
		print post[1]
	db.close()
	
if __name__ == '__main__':test_db()
Copy after login
Related labels:
source:php.cn
Statement of this Website
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
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template
About us Disclaimer Sitemap
php.cn:Public welfare online PHP training,Help PHP learners grow quickly!