备忘:MySQL 数据库使用等

PHP:

$con = mysql_connect("localhost","peter","abc123");
mysql_select_db("my_db", $con);
mysql_query("INSERT INTO Persons (FirstName, LastName, Age) VALUES ('Peter', 'Griffin', '35')");
mysql_close($con);

Python:

import MySQLdb
DB = MySQLdb.connect(host="127.0.0.1", user="root", db="cc", use_unicode=True, charset="utf8")
DBCUR = DB.cursor()
sql = 'INSERT INTO `likesong`(`id`, `name`, `wiki`, `album`) VALUES \
            ("%s","%s","%s","%s");' % (songid, name_hack, wiki_hack, albumid)
DBCUR.execute(sql)
DB.commit() #这句很重要
DB.close()