[PHP Example] Using MySQL w/PHP-VBForums
Results 1 to 3 of 3

Thread: [PHP Example] Using MySQL w/PHP

Threaded View

  1. #1

    Thread Starter
    WiggleWiggle dclamp's Avatar
    Join Date
    Aug 2006

    [PHP Example] Using MySQL w/PHP


    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:
    ("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:
    ("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:
    $query mysql_query($sql);

    $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:
    "SELECT * FROM `members` WHERE memberID='1' LIMIT 1";
    $query mysql_query($sql);
    $result mysql_fetch_array($query);

    //echo $result['COLUMN'];

    echo $result['memberID'];
    // etc...

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

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

Survey posted by VBForums.