Connecting to MYSQL using PHP, PERL DBI & MS ACCESS
How do I work with a MySQL database using PHP?

   1.To merely display the information in your database without the use of a form to call a php script you simply create your HTML document as you would any other web page but instead of the extension of .htm or .html you need to name the file with the extension .phtml. Then within the document itself the section that you'd like to be the PHP code, you begin it with <? and end it with ?>. For instance: 

          <P>These are the products I sell:</P>

          <TABLE BORDER="1">

          <?
             mysql_connect("localhost", "database_user_name", "password");
             $result = mysql(mydatabase, "select * from products");
             $num = mysql_numrows($result);
             $i = 0;

             while($i < $num) {
                echo "<TR>n";
                echo "<TD>n";
                echo mysql_result($result,$i,"prodid");
                echo "</TD>n<TD>";
                echo mysql_result($result,$i,"name");
                echo "</TD>n<TD>";
                echo mysql_result($result,$i,"price");
                echo "</TD>n";
                echo "</TR>n";
                  $i++;}
          ?>
          </TABLE>

     Thus having the loop in the php program create a table with the products listed. NOTE your database user name and password for the database are not written in the file when it's displayed on the Internet so users viewing the source of your webpage will not see your password. [note that database_user_name and password are replaced above with your db user name and password; localhost is not replaced]

   2.When using a CGI script to pull information from a form which has been submitted by a browser you must have the first line of the script have this command on it (Much like perl scripts):

          #!/usr/local/bin/php 



This is a sample perl script that perform mysql connections. This script requires DBI perl module. Please change the following variables inside the script:
$DBuser = "";
$DBpass = ""; 
$DBName = "";
 

/*************cut script below*****************/
#!/usr/bin/perl

use DBI;

    $DBhost = "localhost";
    $DBuser = "";
    $DBpass = ""; 
    $DBName = "";
    

    print("Content-type: text/htmlnn");

    #connect to databases
    $dbh = DBI->connect("DBI:mysql:$DBName:$DBhost",$DBuser, $DBpass);

UPDATE!!! This no longer works: CPAN is testing a new way to handle tables. This is kept for posterity in case it is reverted.

    # pretend query that list tables in the databases
    @tables = $dbh->func( '_ListTables' );
    foreach $table ( @tables )
    {
        print "Table: $tablen";
    }
This is now the correct way to querry tables, along with a slightly better way of getting output:

#list names of all tables in current MySQL database
@tables = $dbh->tables();
foreach $table (@tables)
     {
          print "Table: $tablenr";
     }



Connecting MS Access to a MySQL database

-- You will first need to contact support to request that we give you access to MySQL remotely, e.g., ODBC.
 

***************************************************************************
* WARNING!!! By openning up ODBC access, there are two security risks:    *
*                  *
* 1. IP ACCESS - We strongly encourage clients to use a static IP.        *
*     REASON - When opening access for a given SET of IPs - 67.135.23.*,  *
*        67.135.*, 67.*, etc - access is openned wide for someone   *
*        to access the database unauthorized FROM MULTIPLE IPs.     *
*              A possible HACK attempt may be made.     *
*           *
* 2. NO ENCRYPION - Any information sent via ODBC access is unencrypted.  * 
*                   While compressing data does not encrypt it, we do     *
*                   encourage clients to compress any data sent through   *
*                   ODBC access                                           * ***************************************************************************
 
 

ON LOCAL PC:
1) Download and Install MyODBC 2.50.19 (or most current version) on local
Win95 machine with MS Access installed
                --can download at: http://www.mysql.com/download.html
 

2) Fill in the following settings:

        Windows DNS Name: You can choose the names, must be unique
        Server: This is your domain name or IP address
        MySQL Database Name: The name of your MySQL database
        User: Your MySQL username
        Password: Your MySQL password
        Port: leave blank for default (3306(
        Options; Select "Return Matching Rows"
 

3) To Link a Table:
a) File...Get External Data...Link Tables
b) Under 'Files of Type:', select "ODBC Database"
c) Select Machine Data Source Tab, and select the appropriate Data Source
Name
d) Select the tables(s) to link

Test! Done!
 

Click Here to Go Back