Friday 25 April 2014

An Introduction to database

An Introduction to database
We are going to talking about databases. Now in this article. I am not going to teach you how to setup the database or how to write in database etc. But we just going to be talk about why database important in most real life applications. I am also going to talking about mysql database. Why we need to use the database now you may come across the database before access another database applications so where you can store values with pacific column name so, you can store this values as a array also. you can also do this with Microsoft excel. If you already seen file handling in php. You know we had store things hit counter value in a file and then we had open the file we read the value in and close the file we may then open the value of the file applicant to rewrite another value. This uses huge amount of strength and complication in as well on whole process. Now let say we want to write a value to a file what we doing is we were opening up that file so, reading file data we are then writing a value to a file. What happen if we want to say to include username , password , firstname, surname , website you may have written 100s of records with people username the password. You may want to create some type of login system for this. Now you not going to do file to store this data. You will use database to store which is more secure and quickly accessible. In this case we will use mysql database connection because its one of the fastest database available to you.

Mysql Database
Screenshot1


Mysql database is hosted on to the server. So, it will have its own port number If you open xampp control panel application Screenshot1. You will see we had process running mysql and its running at this moment. From php you don't need to worry about accessing mysql database on to the server. But we do use some functions to connect our database. then we shall connect to our server. Then we use another functions connect to the databases itself. So, you can have variety of amount of databases within mysql. Then you had variety of table inside databases. Now database let say user's Example of user's database.


Example of user's database


database: tutorialsjackpot
--------------------------
table: Users
------------

id    username   password  firstname  surname  website
1     hello          hello123  hello          tell         hello.com
2     How        how456    how's  you         how.com

Here we had database structure in mysql database in users is the table name. Our database name is tutorialsjackpot and the table name is users. Now the way we can access this is we can select our table. Now we are storing the users into and then selecting different value's. So, i can execute something called query which will select specific amount of data from specific row. You also had field called id which is auto-incremental its increment every time. So, each record created. Its automatically increments and this add  unique property and we can define primary key for this id. Primary key is the unique figure unique column in your database.

Now let say i want to select some data so we can say select the username from 'users' where the id is equal to 2. Here users is the table name and this is what we can called query. Its just an English language. But what i had done here is construct general idea something called query about. query does allow us specific syntax to select information from parts. So, what we are doing here is we are selecting the username in column of username from users table where id is equal to 2 means it will give use how. So, this query return the value hello So you can see advance storing inside the database it may look complicated. At this state but when you start using inside php. Php makes it very easy for you to extract data even insert data and perform idea of queries. This done from mysql database. you can also have other tables.


Table: uploads
---------------

id     user_id      location
1      1               logo.jpg
2      1          php.jpg
3      2          art.jpg

we had table say uploads we may allow users to upload files. Now why it is going to be useful. Just add another columns called id, user_id and location. So, the id will again will be auto-increment. But this time user_id What we are doing here is we referencing user_id into the table of users columns id because that is the users id so you can called this columns name anything you like. But i recommended similar structure. So, User id met be 1 and the location of the file which been uploaded. may be logo.jpg and another file is also uploaded by same user so user_id while be 1 and name of the file may be php.jpg. and another file is uploaded by second user hello which user id is 2 so user_id referencing is 2 location art.jpg. So, now what we can do is we can perform the query to say let say user is logged in hello. What we would do we have its id to select things relative hello the id is 1 this is unique to the user hello. So we can say select column name from table name where column name is field value

Example

select location from 'uploads' where user_id is 1


Now What this query here will do it returns values where ever the user_id equals 1. SO, What essentially return.


Output of the query

1      1            logo.jpg

2      1       php.jpg

Now we had selected locations only So, what it will do is it will only print back logo.jpg , php.jpg data. So, what we can do is to speck this out we can select a specific column name So, we can save our time in a program our load time and we can save resources. So, Its essentially for using  database the reason we use its quick and easy way to add information's, that can be easily retrieve we don't have to deal with text files. we don't had to deal with space between file, or commas between characters, hello,bye,goodmorning, So, retrieve from the file we need to open file. we need to use explode function in php to read all this comma's,and to put this into a array. But in database you are creating something you can visualize how extract specific data. You can also update data very very easily with just a single query. So, that was the introduction to databases. Like i said we are going to be using database MySQL and SQL stands for structured query languages. Now was talking about queries. SQL stands for queries. we had structured query which to retrieve, update, delete, create anything inside our table. MYSQL is the name of the databases. we are going to be using.




No comments:

Post a Comment

Thanks For Comment Will get you Soon..

About Me

Welcome to Extra Tutorials! My name is Mohammed and I am the 22 year writer, website developer, and photographer behind the blog. Thanks for visiting! Tutorials Jackpot… In addition to Developer, I love to develop websites and I love to write. Starting a php Blog was inevitable for me. What began as a simple way to share all of my Tutorials with friends and family has developed into my Part time job.

Mohammed Padela

WHAT IS PHP PROGRAMMING

WHAT IS PHP PROGRAMMING
WHAT IS PHP PROGRAMMING

Follow Us

Popular Posts

Designed ByBlogger Templates