Python Insert Data Into MYSQL Try Except - learnit

Home Top Ad

Post Top Ad

Saturday, March 12, 2022

Python Insert Data Into MYSQL Try Except

Python Insert Data Into MYSQL Try Except

What is Python?

Python is a scripting language that is high-level, interpreted, interactive, and object-oriented. Python is intended to be extremely readable. It frequently uses English keywords rather than punctuation, and it has fewer syntactical constructions than other languages.


Python is Interpreted − The interpreter processes Python at runtime. It is not necessary to compile your program before running it. This is comparable to PERL and PHP.


Python is Interactive − To write your programs, you can actually sit at a Python prompt and interact directly with the interpreter.


Python is Object-Oriented − Python supports the Object-Oriented programming style or technique, which encapsulates code within objects.


Python is a Beginner's Language − Python is an excellent language for beginning programmers, as it allows for the creation of a wide range of applications, from simple text processing to web browsers to games.

Python Try Except

In Python, errors are classified into two types: syntax errors and exceptions. Errors are problems in a program that cause the program to stop running. Exceptions, on the other hand, are raised when some internal events occur that disrupt the normal flow of the program. Note: For more information, see Python Errors and Exceptions. Among the most common Exception Errors are:


IOError: if the file can’t be opened

KeyboardInterrupt: when an unrequired key is pressed by the user

ValueError: when built-in function receives a wrong argument

EOFError: if End-Of-File is hit without reading any data

ImportError: if it is unable to find the module


What is MYSQL?

MySQL is an Oracle relational database management system (RDBMS) based on structured query language (SQL).

A database is a well-organized collection of data. It could be anything from a simple shopping list to a picture gallery or a location to store massive amounts of data in a corporate network. A relational database, in particular, is a digital store that collects and organizes data using the relational model. Tables in this model are made up of rows and columns, and all relationships between data elements adhere to a strict logical structure. An RDBMS is simply a collection of software tools used to implement, manage, and query a database.

Example

import mysql.connector
con = mysql.connector.connect(
host = "localhost",
port = "3308",
user = "root",
passwd = "",
database = "reanit"
)
mycursor= con.cursor()

sql="""Insert into tlbuser(id,name,password,other) Values('004','Kong thida','123','user')""" try:
    mycursor.execute(sql)
    con.commit()
except:     con.roolback()
con.close()

No comments:

Post a Comment

Post Top Ad