(★ Dяea Tutorials ★ )-==-[ DataBases in Python ]-==-(★Tutorial no.1★) - Printable Version +- Support Forums (https://www.supportforums.net) +-- Forum: Categories (https://www.supportforums.net/forumdisplay.php?fid=87) +--- Forum: Coding Support Forums (https://www.supportforums.net/forumdisplay.php?fid=18) +---- Forum: Python Programming Language (https://www.supportforums.net/forumdisplay.php?fid=32) +---- Thread: (★ Dяea Tutorials ★ )-==-[ DataBases in Python ]-==-(★Tutorial no.1★) (/showthread.php?tid=24129) Pages:
1
2
|
(★ Dяea Tutorials ★ )-==-[ DataBases in Python ]-==-(★Tutorial no.1★) - Dяea - 12-27-2011
Intro
Well boys and girls, i searched python forum to see what if someone post a Tut about databases in python and i got 0, all i got are questions, so i though of making a Tutorial about making databases in python. What is the Database? Spoiler (Click to View) Database is a collection of well formed and organized data that u can use and make good things. For more Info: Wiki Databases in Python: There are many ways to use Databases in python, like using it through Oracle, MySQL ... etc. But in this tutorial I'll use MySQL to make Databases. Installing MySQL: Check this website it's for Python 2.7 Download Link Make Your First Python Database: First we must import the sqlite module Code: import sqlite3 To create a database insert the next line Code: CreateDB = sqlite3.connect('Py_Database.db') At the above code you can replace the name of the database with this :memory: to make this DB in the memory and delete itself after finishing the program. it's like a temporary DB. Code: CreateDB = sqlite3.connect(':memory:') By this step you have created a database check the working folder and you will find it . Creating a Table Now after creating the database it's the time to add info to the database, first we must create table to save data To execute commands or to talk with the database we have to set the cursor so we can do this Code: curs = CreateDB.cursor() After defining the curs variable at previous step we enter the following Code: curs.execute(''' CREATE TABLE accounts (id INTEGER PRIMARY KEY, account TEXT, pass TEXT, info TEXT) ''') well, in this step we created table with the name 'accounts' then we defined the information we will add to the table in the DB, first we define something like a serial for the data in the table then we define the other information which is in this case, the account then the password for the account and info, and we followed each definition with the type of it whether it's TEXT or INTEGER or REAL ..etc - in this tutorial i make some basic program to save passwords for my accounts as example mile:. Add Info to Table Now we created the database and the table to add data to it, now we add the data, to add data to the database we should choose what table to add data to, then we add the data. Code: curs.execute('''INSERT INTO accounts (account, pass, info) VALUES (?,?,?)''',('email@mailengine.com', 'password', 'other info about the account') The next command is to make the database apply all changes we made here Code: createDB.commit() By this step we are done with creating the database and adding data to it Reading from Database To read from the database enter the following, but first we add the following to connect to the database and work with it Code: createDB = sqlite3.connect('Py_Database.db') Then the next line to select which table to deal with Code: read = curs.execute('''SELECT * FROM accounts''') Then the next code to read from the database Code: for record in read: Here is a basic example for password keeper to save my passwords with accounts, it's basic and need a lot to be good one but it's as i said ... an example Link: http://pastebin.com/jBdR01QG Screenshots: Figure-1 (Click to View) Figure-2 (Click to View) Figure-3 (Click to View) This is the end. Thanks for reading my tutorial :-) Stay Tuned for the next Tut RE: (★ Jess Tutorials ★ )-==-[ DataBases in Python ]-==-(★Tutorial no.1★) - Pikachu - 12-30-2011 Very nice tutorial for beginners. I have been getting very good in this programming language. I hope to improve. RE: (★ Jess Tutorials ★ )-==-[ DataBases in Python ]-==-(★Tutorial no.1★) - 8i8 - 12-31-2011 Nice tutorial, i'll be sure to read it all later on. RE: (★ Jess Tutorials ★ )-==-[ DataBases in Python ]-==-(★Tutorial no.1★) - MineCrack - 01-02-2012 Nice, this is where I will start to learn. RE: (★ Jess Tutorials ★ )-==-[ DataBases in Python ]-==-(★Tutorial no.1★) - Pikachu - 01-05-2012 Nice looking Tutorials. I am experienced in this language and I have followed similar Tutorials. RE: (★ Jess Tutorials ★ )-==-[ DataBases in Python ]-==-(★Tutorial no.1★) - Dяea - 03-22-2012 2 months without any posts? That cant be true? Anyone love it ;)? RE: (★ Jess Tutorials ★ )-==-[ DataBases in Python ]-==-(★Tutorial no.1★) - Grin - 03-22-2012 Now before I read it. Thank you. This seems very well informed. If I have questions I shall post them:$ RE: (★ Jess Tutorials ★ )-==-[ DataBases in Python ]-==-(★Tutorial no.1★) - Dяea - 03-22-2012 Grin if you got any problems just write to me :-) What tutorial will you guys see next? RE: (★ Jess Tutorials ★ )-==-[ DataBases in Python ]-==-(★Tutorial no.1★) - Dяea - 03-23-2012 What do you guys think about my tutorial ? RE: (★ Jess Tutorials ★ )-==-[ DataBases in Python ]-==-(★Tutorial no.1★) - Dяea - 03-24-2012 What should my next tutorial be about? |