Learn about Python's database of those things

Source: Internet
Author: User
Tags rollback virtual environment

A about python built-in packages are transferred to pycharm

    1. problem:python has some third-party libraries installed, but it can't be called in Pycharm?
    2. Answer: Because third- party libraries are stored in the system environment after they are installed through Pip, and pycharm is a virtual environment, you need to add the third-year library you need to your project.
    3. action:file-setting-python file-python interpreter- Click +to search for the required package -install Packing, you can use this new package.

Two Python vs . MySQL operations

  1. The relationship between Python and the database is linked through the associated APIs . Depending on the database and different versions of python, the required APIs are different . Take the native installation as an example:python3.6+mysql, so the installation is pymysql. Installation can also be done via pip.exe install pymysql or download package directly.
  2. The general idea is: Open database connection, database related operations , close the connection
  3. Example:
  4. (1). Open a database connection
  5. The. Connect () function is used to create a connection, write the host, username, password, existing database, port number
  6. (2). Create a table

  7. (3), inserting data

  8. . Cursor () is the method used to get Python to execute the MySQL command, that is, to obtain an operation cursor; The Execute () function is the command used to execute the SQL statement, the. Commit () function is used to commit the transaction, and only after the transaction has been committed for the database to take effect; rollback () Is that when the database is modified, uncommitted (commit) can be returned to the pre-unmodified state by rolling back (rollback).

  9. After you have finished working with the database, you need to close the connection and use the. Close () method. If you do not close the connection, it will cause the system to crash when more people are using it.
  10. Other operations on the database are not listed, as above.
  11. There are several other commonly used commands in database operations:
  12. (1). Fetchall (): Used to receive all of the returned result rows (rows), which returns multiple tuples if NULL is returned ();
  13. (2). Fetchone (): Returns a single tuple, which is a record (row), and returns none if no result is found
  14. Summary: The first time to write these a bit of chaos, every day to take some time out of the record, hope to solid foundation!!!

Learn about Python's database of those things

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.