Home >Backend Development >PHP Tutorial >[Newbie asking for help] Why does pymysql report an EOF error when linking to the database?

[Newbie asking for help] Why does pymysql report an EOF error when linking to the database?

WBOY
WBOYOriginal
2016-09-03 00:14:111570browse

1. An error occurred when using pymysql to connect to the database
Error code:

<code>SyntaxError: unexpected EOF while parsing
Process finished with exit code 1
</code>

2. Below is my code

<code>import pymysql

## 链接数据库
connection = pymysql.connect(host = 'localhost',user = 'root',passwd = 'gangan',db = 'qiandao')
try:
    cur = connection.cursor()
    cur.execute("SELECT fk_si_user,si_trueName from fbl_stuinfo where si_trueName like '甘%'")

    data = cur.fetchall()

    for row in data:
       print('%s\n%s'%row)
    
    cur.close()
    connection.commit()
    </code>

3.What does the EOF error mean? What are the general solutions? Python 3.5 newbie needs advice

Reply content:

1. An error occurred when using pymysql to connect to the database
Error code:

<code>SyntaxError: unexpected EOF while parsing
Process finished with exit code 1
</code>

2. Below is my code

<code>import pymysql

## 链接数据库
connection = pymysql.connect(host = 'localhost',user = 'root',passwd = 'gangan',db = 'qiandao')
try:
    cur = connection.cursor()
    cur.execute("SELECT fk_si_user,si_trueName from fbl_stuinfo where si_trueName like '甘%'")

    data = cur.fetchall()

    for row in data:
       print('%s\n%s'%row)
    
    cur.close()
    connection.commit()
    </code>

3.What does the EOF error mean? What are the general solutions? Python 3.5 newbie needs advice

You should post all the errors. This error is not necessarily because mysql cannot be connected, it is most likely a problem with your print

print(r'%sn%s'%row) try adding an r in front of it

Statement:
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn