PHP and MySQL Library Tutorial

General
Site Root
Database Home
Conect to MySQL
MySQL_Login.php
nav.php
dump.php

Clean Up resets the
database to contain
a few sensible
records.

Download Tutorial

Database
Create
Drop

Person Table
Create
Drop

Insert
Delete
Update
Search
Date-Search

Row Dump
Better View 
Table View 
Form View

Book Table
Create
Drop

Insert
Delete
Update
Search




Table View 
Form View

Loan Table
Create
Drop

Insert
Delete

Search




Table View

Documentation
Data Requirements
User Interface Design
Entity Relationship Diagrams
Data Flow Diagrams
Data Dictionary
Implementation Notes
Table Designs
Goals, Testing and Appraisal

Note - Create, Drop and Clean Up would be hidden on a real life system.
Contact - nbauers at samphire dot demon dot co dot uk
Copyright © - You may use and reproduce this material in a "not for profit" setting.

Connect Succeeded

The PHP code below does the job.


<?php
  require "../MySQL_Login.php";    // Contains MySQL login details
  $link = mysql_connect($host, $user, $password) or die(mysql_error());  
  // Normally some interesting processing would take place here.  
  mysql_close($link);
?>

Explanations:

Possible reasons for failure:


Code Listing : connect.php

<?php
  require "../MySQL_Login.php";    // Contains host, username, password, and database	
  $link   = mysql_connect($host, $user, $password) or die(mysql_error());    
  // Normally some interesting processing would take place here.  
  mysql_close($link);
?>

<html>
<head>
<title>CONNECT TO MySQL</title>
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1">
</head>

<body>

<?php include "nav.php"; ?>

<h2>Connect Succeeded</h2>
<p>The PHP code below does the job.</p>
<hr />
<pre>&lt;?php
  require "../MySQL_Login.php";    // Contains MySQL login details
  $link = mysql_connect($host, $user, $password) or die(mysql_error());  
  // Normally some interesting processing would take place here.  
  mysql_close($link);
?&gt;
</pre>
<hr />
<p><strong>Explanations:</strong></p>
<ul>
  <li><strong>MySQL_Login.php</strong> contains host, login and database details 
    for MySQL.</li>
  <li><strong>mysql_connect</strong> makes the connection if the login credentials 
    are OK.</li>
  <li><strong>$host, $user and $password</strong> all came from the MySQL_Login.php 
    file.</li>
  <li><strong>or die(mysql_error())</strong> kills the script with an error message 
    if the connection failes for any reason.</li>
  <li><strong>mysql_close</strong> closes the link. If you forget this line, the 
    link will eventually be closed for you.</li>
</ul>
<p><strong>Possible reasons for failure:</strong></p>
<ul>
  <li>One or more of $host, $user and $password are incorrect.</li>
  <li>File permissions on the server might be wrong. Execute permission is needed.</li>
  <li>The web server might not be running.</li>
  <li>PHP might not be set up and running.</li>
  <li>MySQL might not be set up and running.</li>
</ul>

<?php 
  include "dump.php";
  dump_page(basename($_SERVER[SCRIPT_FILENAME]));  // Display the code of this page
?>

</body>
</html>