Mar-22-2020, 07:49 AM
(Mar-22-2020, 07:08 AM)ndc85430 Wrote: Do you know any SQL? If not, you'll want to at least learn the basics of creating tables and inserting rows. Seems like your question is more of an SQL one than a Python one at this point.
ndc85430,
I do know some SQL. I found some descent reference material that I will share below; however it doesn't demonstrate in ways that I understand how to pass the current Python3 variables that I am working with. (allOpinion, allTitle and allURL) to a MySQL database table.
Referring back to the documentation I see that you are right on looking at the code better for MySQL. I am setting up to do an INSERT Python Variable pass off to a MySQL Table.
The Instructions are found here:
The code used to demonstrate this process is below:
import mysql.connector from mysql.connector import Error def insertVariblesIntoTable(id, name, price, purchase_date): try: connection = mysql.connector.connect(host='localhost', database='Electronics', user='pynative', password='pynative@#29') cursor = connection.cursor() mySql_insert_query = """INSERT INTO Laptop (Id, Name, Price, Purchase_date) VALUES (%s, %s, %s, %s) """ recordTuple = (id, name, price, purchase_date) cursor.execute(mySql_insert_query, recordTuple) connection.commit() print("Record inserted successfully into Laptop table") except mysql.connector.Error as error: print("Failed to insert into MySQL table {}".format(error)) finally: if (connection.is_connected()): cursor.close() connection.close() print("MySQL connection is closed") insertVariblesIntoTable(2, 'Area 51M', 6999, '2019-04-14') insertVariblesIntoTable(3, 'MacBook Pro', 2499, '2019-06-20')I am setting up my Database as follows for this script:
PythonMariaDB1 (Database)
Single_No_Loop (Table)
allTitle - VARCHAR - 250 (Column #1)
allOpinion - LONGTEXT (Column #2)
allURL - VARCHAR - 250 (Column #3)
I will use the above example code as reference and hope I can integrate it properly into this existing one. I will update either way (work or fail).
Thank you for your response sir!
Best Regards,
Brandon Kastning
“And one of the elders saith unto me, Weep not: behold, the Lion of the tribe of Juda, the Root of David, hath prevailed to open the book,...” - Revelation 5:5 (KJV)
“And oppress not the widow, nor the fatherless, the stranger, nor the poor; and ...” - Zechariah 7:10 (KJV)
#LetHISPeopleGo
“And oppress not the widow, nor the fatherless, the stranger, nor the poor; and ...” - Zechariah 7:10 (KJV)
#LetHISPeopleGo