[ACCEPTED]-Getting return values from a MySQL stored procedure in Python, using MySQLdb-mysql
What I had to do is modify the Python code 6 to use execute() instead of callproc(), and 5 then use the fetchone() to get the results. I'm 4 answering it myself since mluebke's answer 3 wasn't entirely complete (even though it 2 was helpful!).
mysql_cursor.execute( "call get_lastpoll();" )
results=mysql_cursor.fetchone()
print results[0]
This gives me the correct 1 output:
2009-02-19 17:10:42
See https://stackoverflow.com/a/52715128/2391795 for advanced usage of fetchone
, fetchall
, etc.
callproc
also works fine, you don't need to use 1 execute
:
mysql_cursor.callproc( "get_lastpoll", () )
result = mysql_cursor.fetchone()
You still have to fetch the results.
results = cursor.fetchone()
or
results = cursor.fetchall()
0
From the API documentation for the MySQLdb
library. You 5 will need to call cursor_obj.nextset()
before you will see the 4 result set returned by the stored procedure. This 3 is because the call to the stored procedure 2 creates a result set. The result sets returned 1 by the stored procedure follow.
More Related questions
We use cookies to improve the performance of the site. By staying on our site, you agree to the terms of use of cookies.