Omowe
This Python Code Outputs its Data to a MySQL Database

This code creates a connection to a MySQL database and uses a cursor object to execute an INSERT statement that inserts the values of the number_1, number_2, and sum variables into a table called numbers. It then commits the transaction and closes the cursor and connection. Finally, it sends the two numbers and the sum to Airtable using the webhook, and checks the status code of the response to see if the request was successful.

Remember to replace the placeholders in the mysql.connector.connect() function with the actual hostname, username, password, and database name for your MySQL database.

import requests
import mysql.connector

# Replace YOUR_WEBHOOK_URL with the actual webhook URL from Airtable
webhook_url = "YOUR_WEBHOOK_URL"

# Prompt the user for the first number
number_1 = int(input("Enter the first number: "))

# Prompt the user for the second number
number_2 = int(input("Enter the second number: "))

# Calculate the sum of the two numbers
sum = number_1 + number_2

# Connect to the MySQL database
conn = mysql.connector.connect(
  host="hostname",
  user="username",
  password="password",
  database="database_name"
)

# Create a cursor object
cursor = conn.cursor()

# Execute an INSERT statement to insert the values into the database
cursor.execute("INSERT INTO numbers (number_1, number_2, sum) VALUES (%s, %s, %s)", (number_1, number_2, sum))

# Commit the transaction
conn.commit()

# Send the two numbers and the sum to Airtable using the webhook
response = requests.post(webhook_url, json={"number_1": number_1, "number_2": number_2, "sum": sum})

# Check the status code of the response to see if the request was successful
if response.status_code == 200:
  print("Successfully sent numbers and sum to Airtable and MySQL")
else:
  print("Failed to send numbers and sum to Airtable")

# Close the cursor and connection
cursor.close()
conn.close()

 

Facebook
Twitter
LinkedIn
Pinterest

Leave a Reply

Your email address will not be published. Required fields are marked *

This is an Advertorial

Learn how to build digital products without writing a single line of code

Build anything you can dream of without writing code or hiring a developer

Our non-technical students start companies using tools like Bubble, Softr , Elementor and Airtable. It’s easier, faster and more fun.

No matter what your background is, our lessons are designed to figure out what you don’t know and fill in the gaps

Join our learning community of soulmates, learn at your own pace and stay motivated to reach your objectives.

Begin Your No-Code Journey.


Training Mode : in-class
Location : E-349 Ikota Shopping Complex, VGC, Ajah, Lagos
Fees : N150,000