This article mainly introduces the example of using python to connect to mysql to call the stored procedure. For more information, see
The code is as follows:
#! /Usr/bin/env python
#-*-Coding: utf8 -*-
Import MySQLdb
Import time
Import OS, sys, string
Def CallProc (id, onlinetime ):
''' Call the stored procedure,
Input parameter: Number, online time, output: Account, password;
Use the output parameter method '''
Accname =''
Accpwd =''
Conn = MySQLdb. connect (host = 'localhost', user = 'root', passwd = '000000', db = 'ceshi ')
Cur = conn. cursor ()
Cur. callproc ('proctest', (id, onlinetime, accname, accpwd ))
Cur.exe cute ('select @ _ proctest_2, @ _ proctest_3 ')
Data = cur. fetchall ()
If data:
For rec in data:
Accname = rec [0]
Accpwd = rec [1]
Cur. close ()
Conn. close ();
Return accname, accpwd
Def CallProct (id, onlinetime ):
''' Call the stored procedure,
Input parameter: Number, online time, output: Account, password;
Use the select return record method '''
Accname =''
Accpwd =''
Conn = MySQLdb. connect (host = 'localhost', user = 'root', passwd = '000000', db = 'ceshi ')
Cur = conn. cursor ()
Cur. nextset ()
Cur.exe cute ('Call ptest (% s, % s) ', (id, onlinetime ))
Data = cur. fetchall ()
If data:
For rec in data:
Accname = rec [0]
Accpwd = rec [1]
Cur. close ()
Conn. close ();
Return accname, accpwd
Name, pwd = CallProct (1, 0)
Print name, pwd