+ Reply to Thread
Results 1 to 8 of 8

Thread: MySQL Tutorial

  1. #1
    Bobswat is offline x10Hosting Member Bobswat is an unknown quantity at this point
    Join Date
    Apr 2005
    Location
    Walton, NY
    Posts
    52

    MySQL Tutorial

    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 Code:
    <?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 by Bobswat; 10-27-2005 at 09:27 PM. Reason: forgot something
    -J.P.

  2. #2
    Bobswat is offline x10Hosting Member Bobswat is an unknown quantity at this point
    Join Date
    Apr 2005
    Location
    Walton, NY
    Posts
    52

    Re: MySQL Tutorial

    Is this helpful for anyone? if not ill just not worry about adding anymore to it
    -J.P.

  3. #3
    Matthews255's Avatar
    Matthews255 is offline x10 Lieutenant Matthews255 is an unknown quantity at this point
    Join Date
    Mar 2005
    Location
    Cambs, UK
    Posts
    413

    Re: MySQL Tutorial

    Please add more, its a really good tut.

    If you put that on a web page and submit it to Pixel2Life it would be cool.

    you could say, seen it here first.


    EDIT: what would be REALLY helpful is a code to delete posts from my sql tables.

    Like deleting entrys from my news database.
    Last edited by Matthews255; 11-01-2005 at 11:22 AM.

  4. #4
    Bobswat is offline x10Hosting Member Bobswat is an unknown quantity at this point
    Join Date
    Apr 2005
    Location
    Walton, NY
    Posts
    52

    Re: MySQL Tutorial

    Well to delete entires you would do:

    PHP Code:
    <?php
    $value 
    'value';

    mysql_query("DELETE from `tablename` WHERE `fieldname`= '$value' LIMIT 1");
    ?>
    you would just change the value of the $value variable to whatever criteria you need.

    DELETE from is the command, obviously to delete.

    `tablename` is the name of the table on the database you are deleting the entry from

    WHERE
    is the filtering agent to declare which row to delete

    `fieldname`
    is the field you are searching by

    `value`
    is the value that the `fieldname` holds in the row, the one which you wish to delete

    LIMIT 1
    is sort of a safety measure to make sure that you don't delete like 500 rows that match the criteria from your table, unless thats what you are trying to do. Something such as deleting all records where the `fieldname` is equal to lets say '4' would be a situation where you would not do any sort of LIMIT.

    any other suggestions are welcome. If this tutorial is helping any of you guys, then please let me know by posting. Also post any requests that you would like in here, it doesn't just have to pertain to just MySQL alone, anything php or html is also acceptable and if I get enough requests I will do a php tutorial also.
    Last edited by Bobswat; 01-14-2008 at 03:48 AM. Reason: forgot to explain LIMIT 1
    -J.P.

  5. #5
    klnce is offline x10Hosting Member klnce is an unknown quantity at this point
    Join Date
    Nov 2007
    Posts
    35

    Re: MySQL Tutorial

    i need that config file. Because i need to connect to mysql from php or by asp.......... plz post it........



    My site is

    http://klnce.elementfx.com
    Edit:
    i need that config file. Because i need to connect to mysql from php or by asp.......... plz post it........
    Last edited by klnce; 01-15-2008 at 03:03 PM. Reason: Automerged Doublepost

  6. #6
    Bobswat is offline x10Hosting Member Bobswat is an unknown quantity at this point
    Join Date
    Apr 2005
    Location
    Walton, NY
    Posts
    52

    Re: MySQL Tutorial

    Here is a copy of the file I use:

    PHP Code:
    <?php
    $username 
    'your_username_here';
    $password 'your_password_here';
    $host 'localhost';
    $database 'your_database_here';

    mysql_connect($host$username$password) or die(mysql_error());
    mysql_select_db($database) or die(mysql_error());

    ?>
    use
    PHP Code:
    include('path_to_connection'); 
    at the top of all the files that need MySQL access


    That will work for php, and as of now, x10 does NOT support asp, at least thats what ive read in the forums. You may PM them and ask for it to be added to your account, they have done it on an account-by-account basis before.

    good luck!


    Anyone else need anything? Feel free to post in here
    Last edited by Bobswat; 01-17-2008 at 01:52 PM.
    -J.P.

  7. #7
    mittalmak is offline x10Hosting Member mittalmak is an unknown quantity at this point
    Join Date
    Nov 2007
    Posts
    2

    Re: MySQL Tutorial

    thanx for the tut......

  8. #8
    port5900's Avatar
    port5900 is offline x10 Sophmore port5900 is an unknown quantity at this point
    Join Date
    Jan 2008
    Location
    NYC BrOokLyn!
    Posts
    150

    Re: MySQL Tutorial

    Thank you, MySql is some thing I was staying away from till now.

+ Reply to Thread

Similar Threads

  1. [PHP] MySQL and PHP
    By Bryon in forum Tutorials
    Replies: 43
    Last Post: 03-24-2011, 07:27 AM
  2. MySQL server address HELP :S
    By rinnerz.com in forum Free Hosting
    Replies: 5
    Last Post: 07-09-2006, 10:25 AM
  3. in here MySQL version????
    By winUSD in forum Free Hosting
    Replies: 4
    Last Post: 05-09-2006, 08:44 AM
  4. Have a problem with my forum
    By tikloos in forum Scripts & 3rd Party Apps
    Replies: 43
    Last Post: 01-19-2006, 01:14 AM
  5. mysql tutorial
    By dosworld in forum Free Hosting
    Replies: 3
    Last Post: 05-31-2005, 04:19 PM

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
x10hosting free hosting for the masses
dedicated servers