MySQL: The Basics
Covered in this: I am going to attempt to explain data insertion, Update queries, filtering clauses, all the parts of a query, and probably more, I just forgot what else. Please bear with me on this, it's my first tutorial, and I'll probably edit it a million times.
MySQL and its uses: MySQL Is the language you use to communicate with a Database(DB). So say you have a basic form, and you want to add members to your website after you create the login system. You would want the members and their information added to the database after each account is registered. Below is an example of a simple MySQL query used along with php.
PHP:
<?php
include('yourconnection.php');
session_start();
$username = $_POST['username'];
$password = $_POST['password'];
mysql_query("INSERT INTO `table name`(`username`, `password`) VALUES('$username', '$password')") or die(mysql_error());
?>
ok, so now we'll go over each part of the query
1. mysql_query() - The php function used for a MySQL query
2. INSERT INTO - This is the actual action of the query
some other examples are:
SELECT - Used to get information from the DB
UPDATE - Used to update existing information
INSERT - used above, to add data to a table
3. `table name` - the name of the table you are modifying
4. (`username`, `password`) - The names of the rows the data will go into, these are only used in an INSERT INTO query, and they are optional, its best to use them though, so if your table changes, the data will still be inserted into the correct row.
5. VALUES('$username', '$password') - this is the data to be inserted in the table, they correspond with the previous piece of code, such that:
`username` will be given the value '$username' If the optional item is not used, then it will go in order of the rows in your table. which is why you should specify the optional, incase you change the rows in your table.
6. or die(mysql_error()); - If there is an error with your query code, a mysql error will be generated telling you the problem with it. ALWAYS USE THIS AFTER ANY QUERY.
Examples of other queries:
SELECT - SELECT `row name` FROM `table name`
UPDATE - UPDATE `table name` WHERE `row name` = '$variable'
Data Filtering:
there are certain clauses we can use to filter data the way we want it such as:
WHERE - used in the above example, it says to update the table SO the row you choose is given the value of the variable
LIKE - used mainly with wildcards and searches on a site
If anybody would like me to continue and add more things to this, post a reply and tell me so, also if anyone would like help with anything MySQL, PHP, or HTML related send me a message via aim, my screen name is
bob from walton,Sorry, I just got bored of writing for now, tell me what else you need help with and ill add it to this ASAP.
Last edited: