Python3 pymysql has been confused.

import pymysql
import time
import datetime
-sharp 
db = pymysql.connect("localhost","root","aaaaaa","getlist" )
cursor = db.cursor()
sql="INSERT INTO t_mall VALUES (0,%s,%s,%s)"
try:
   -sharp SQL
   cursor.execute(sql % ("http://baidu.com", "", ""))
   -sharp 
   db.commit()
except:
   -sharp 
   db.rollback()

-sharp 
db.close()

No error message is displayed during execution, but the data is not inserted. What is the reason?

Jul.08,2021

you can troubleshoot the problem from these angles
1, and print out the sql string within the execute () directly

check the sql string for syntax errors, and modify
if there are any errors.

2. Execute the sql statement printed above manually to see if you can enter the database

.
1. If there is no problem, execute 2. If you can enter the database, check for database connection problems

3. Check whether curosr connects to the database successfully.


feels like a command is missing and does not select a table to use:
cursor.execute ('use tasking answer')


first of all, it is not recommended to add try except to the first test, and the error cannot be displayed, and you will not see the error.

Furthermore, if you insert Chinese characters, you'd better set the character encoding before insertion: cursor.execute ('SET NAMES utf8mb4;')


visually, it is a field that does not specify the value of the inserted field.


this, you need to add table_name (field1, field2.)

MySQL Query : SELECT * FROM `codeshelper`.`v9_news` WHERE status=99 AND catid='6' ORDER BY rand() LIMIT 5
MySQL Error : Disk full (/tmp/#sql-temptable-64f5-1eabab8-2071.MAI); waiting for someone to free some space... (errno: 28 "No space left on device")
MySQL Errno : 1021
Message : Disk full (/tmp/#sql-temptable-64f5-1eabab8-2071.MAI); waiting for someone to free some space... (errno: 28 "No space left on device")
Need Help?