python调用mysql存储过程没有反应
ringa_lee
ringa_lee 2017-04-17 17:49:40
[Python讨论组]

建表:

drop table if exists `Account`;
CREATE TABLE `Account` (
`id` BIGINT(20) NOT NULL,
`Name` VARCHAR(100) NOT NULL,
`pwd` VARCHAR(100) NOT NULL,
`times` BIGINT(20) UNSIGNED NOT NULL DEFAULT '0'
)ENGINE=InnoDB

插入数据:

INSERT INTO `Account` (`id`, `Name`, `pwd`, `times`) VALUES
(1, 'Messiah', '59data', 0),
(2, 'zmx', 'data', 0),
(3, '59store', '盖亚', 1);

建立储存过程:

DELIMITER //
DROP PROCEDURE IF EXISTS `proctest`//
CREATE PROCEDURE`proctest`()
BEGIN
insert into  Account
VALUES(5,'盖亚','59store',9);
END //

Python 脚本:

#!/usr/bin/env python
# -*- coding: utf8 -*-
import MySQLdb
import time
import os, sys, string
conn = MySQLdb.connect(host='192.168.1.59',user='59data',passwd='59store',db='test')
cur =conn.cursor()
#sql='call proctest'
#cur.execute(sql)
cur.callproc('proctest',())
cur.close()
conn.close()

Python 脚本用 MySQLdb 模块 callproc 方法调用 mysql 存储过程没有任何反应

ringa_lee
ringa_lee

ringa_lee

全部回复(2)
ringa_lee

猜测应该是缺少事务提交

from django.db import transaction

with transaction.commit_manually():
    conn = MySQLdb.connect(host='192.168.1.59',user='59data',passwd='59store',db='test')
    cur =conn.cursor()
    try:
        cur.callproc('proctest')
        transaction.commit()
    except:
        transaction.rollback()
    finally:
        cur.close()
        conn.close()
    
怪我咯

你确定密码和用户名都对,数据库中已经有db-test?

热门教程
更多>
最新下载
更多>
网站特效
网站源码
网站素材
前端模板
关于我们 免责申明 意见反馈 讲师合作 广告合作 最新更新 English
php中文网:公益在线php培训,帮助PHP学习者快速成长!
关注服务号 技术交流群
PHP中文网订阅号
每天精选资源文章推送
PHP中文网APP
随时随地碎片化学习

Copyright 2014-2025 https://www.php.cn/ All Rights Reserved | php.cn | 湘ICP备2023035733号