0

i am having a python program which has got a numpy array with a single element say a=['this is the element'] i need to insert this value to my database(MySQL).

i used execute() but it is showing an attribute error

my sql part to select data from table is this :

import pandas as pd
import mysql.connector
mysql_cn=mysql.connector.connect(user='root', password='',
                              host='127.0.0.1',port='3388',
                              database='proj')

X = pd.read_sql('select stamp from test;', con=mysql_cn)
mysql_cn.close()

so what has to be done since mysql_cn.execute() is not working? i also tried pd.to_sql but it is also not working

this is the error for execute()

Traceback (most recent call last):
  File "C:\Python34\data\test.py", line 132, in <module>
    haa=mysql_cn.execute('select stamp from test;')// this is my simple query not my actual query
AttributeError: 'MySQLConnection' object has no attribute 'execute'
4
  • what is the error? Commented Mar 13, 2017 at 9:54
  • when i use mysql_cn.execute() i am getting an attribute error saying execute is not an attribute Commented Mar 13, 2017 at 9:55
  • because execute requires the query as a parameter. Commented Mar 13, 2017 at 9:59
  • actually i skipped the query while commenting.. i tried with query.. but even if i have a query its showing attribute error Commented Mar 13, 2017 at 10:00

1 Answer 1

1

You need a cursor. You have to create a cursor from your mysql_cn then you can call execute on the cursor.

cursor = mysql_cn.cursor()
# Now call cursor.execute ....
Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.