python如何连接MySQL数据库
#!/usr/bin/env python
# -*-coding:UTF-8-*-#这一句告诉python用UTF-8编码
#=========================================================================
#
# NAME: Python MySQL test
#
# AUTHOR: benyur
# DATE : 2004-12-28
#
# COMMENT: 这是一个python连接mysql的例子
#
#=========================================================================
"""
***** This is a MySQL test *****
select:
conn=Connection()
conn.select_db('test')
cur=conn.cursor()
cur.execute('select * from user')
cur.scroll(0)
row1=cur.fetchone()
row1[0]
row1[1]
row1[2]
insert:
cur.execute('insert into user (name,passwd) values('benyur','12345')')
cur.insert_id()
update:
cur.execute('update user set passwd='123456' where name='benyur'')
delete:
cur.execute('delete from user where id=2')
**********************************
"""
from MySQLdb import *
def conn():
conn=Connection()
conn.select_db('test')
cur=conn.cursor()
cur.execute('select * from user')
cur.scroll(0)
row1=cur.fetchone()
row1[0]
row1[1]
row1[2]
def usage():
print __doc__
if __name__=='__main__':
usage()
MySQLdb下载地址:http://sourceforge.net/projects/mysql-python/
下载解压缩后放到%Python_HOME%Libsite-packages目录中,python会自动找到此包。
MySQLdb基本上是MySQL C API的Python版,遵循Python Database API Specification v2.0。
相关文档:
插入一条记录:
mysql> insert into table_name (column_name1,column_name2,.) values (value1,value2,..);
更新一条记录:
mysql> update tbl_name
s ......
1.今天的程序发布到服务器,过了一晚后发现程序不能访问了,好像是连接池问题。错误如下: [log4j:] 2009-10-30 17:32:10,353 - com.school.dao.OperaDAO -65984388 [http-8080-12] ERROR com.school.dao.OperaDAO - find all failed
org.hibernate.exception.JDBCConnectionException: could not execute query ......
关于php应该在何时调用mysql_close()以及pconnect方式和传统方式有何种区别收藏
以前我一直认为,当php的页面执行结束时,会自动释放掉一切。相信很多人都跟我想的一样。但事实证明并不是这样。比如session就不会随着页面执行完毕而释放。
php的垃圾回收机制,其实只针对于php本身。对于mysql,php没权利去自动去释放它的 ......
MYSQL中只有INNODB和BDB类型的数据表才能支持事务处理!其他的类型是不支持的!
$lnk = mysql_connect("localhost", "root", "");
mysql_select_db("test");
mysql_query("BEGIN");
$query = mysql_query("INSERT INTO test VALUES(1, 'yangjun')&quo ......