Results 1 to 3 of 3

Thread: [PHP Example] Using MySQL w/PHP

  1. #1

    Thread Starter
    WiggleWiggle dclamp's Avatar
    Join Date
    Aug 2006
    Posts
    3,527

    [PHP Example] Using MySQL w/PHP

    NEW TUTORIAL UNDER CONSTRUCTION

    Here i am going to show you (quickly) how to use MySQL in PHP.

    If you are not familiar with MySQL, then take a look here

    Connecting to MySQL Server
    The following is generic code to connecting to a MySQL Server. Typically you will be using your local mysql server on your computer / web server

    PHP Code:
    <?php
    mysql_connect
    ("localhost""USERNAME""PASSWORD") or die("could not connect to MySQL server");
    ?>
    Selecting a MySQL Database
    Before you can make MySQL queries, you need to select a database that has the information you need. This typically comes after you connect to a database

    PHP Code:
    <?php
    mysql_select_db
    ("databasename") or die("could not select MySQL database");
    ?>
    Preforming a Query (Update/Insert/Delete/Truncate/Num_Rows)
    A query is a message sent to the sql server either asking for information, or telling it to input or change information. This example shows how to Update/Insert/Delete/Truncate from database

    PHP Code:
    <?php
    $sql 
    "YOUR SQL HERE"// REFER TO THE MYSQL HELP LINK IN THIS POST AND MY SIGNATURE
    $query mysql_query($sql);

    // THAT WILL PREFORM YOUR QUERY. IF YOU DID A NUM_ROWS QUERY:
    $numrows mysql_num_rows($query);

    // then you can use $numrows in an IF statement
    ?>
    Preforming a Query (Select)
    Select query will be the most used query (for most people). It allows you to select rows from a table with many option for selecting the correct row. I will show 2 examples. 1) Selecting just one row; 2) selecting an ARRAY of rows.

    PHP Code:
    <?php
    $sql 
    "SELECT * FROM `members` WHERE memberID='1' LIMIT 1";
    $query mysql_query($sql);
    $result mysql_fetch_array($query);

    //USAGE:
    //echo $result['COLUMN'];

    echo $result['memberID'];
    echo 
    $result['name'];
    echo 
    $result['email'];
    // etc...
    ?>

    More coming soon!
    Last edited by dclamp; Mar 25th, 2008 at 12:08 AM.

  2. #2
    Frenzied Member
    Join Date
    Sep 2005
    Posts
    1,547

    Re: [PHP Example] Using MySQL w/PHP

    Thanks .

  3. #3

    Thread Starter
    WiggleWiggle dclamp's Avatar
    Join Date
    Aug 2006
    Posts
    3,527

    Re: [PHP Example] Using MySQL w/PHP

    you're welcome! and thank you
    My usual boring signature: Something

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Click Here to Expand Forum to Full Width