CSC 465 Getting Started with phpMyAdmin
Part 1: phpMyAdmin is a
GUI to work with the department’s MySQL database on webdev.
1.
Download the file from http://people.uncw.edu/mferner/CSC465/DataFiles/my_guitar_shop1.sql
2.
If you have never used MySQL, you
will find a text file containing your password in your home directory on webdev or in an email.
3.
Log into phpMyAdmin: http://webdev.cislabs.uncw.edu/phpmyadmin
4.
On the left side of
the screen, select the database that corresponds to your UNCW username. (This may be your only choice.)
5.
If necessary, change
your password by doing the following:
a.
Click on the Home
icon in the upper left area of the screen
b.
In the General
Settings area, click Change Password
c.
Enter your new
password in both text boxes, and click the Go button
6. Click on the Import tab. Use the Browse button to find the downloaded
SQL file, and click the Go button. This
will create two tables and populate them with data.
Part 2: Use PHP to connect to the
database:
1.
Create the following file named mysqli_conect.php substituting your personal data for the
first, second, and last values.
2.
Upload it to webdev
outside of your public_html directory and set
permissions to 644
<?php #
name this file: mysqli_connect.php
// This file contains the database access
information.
// It establishes a connection to MySQL and selects the database to use.
// Set the database access information as constants:
DEFINE ('DB_USER', 'your user name');
DEFINE ('DB_PASSWORD', 'your sql/phpMyAdmin
password');
DEFINE ('DB_HOST', '127.0.0.1');
DEFINE ('DB_NAME', 'your user name');
// Make the connection:
$dbc= mysqli_connect
(DB_HOST, DB_USER, DB_PASSWORD, DB_NAME)
OR die ('Could not connect to MySQL: ' . mysqli_connect_error()
);
echo 'Connection successful!';
?>
3. Create another simple script with
just the code below.
4. Upload it to webdev
placing it inside the public_html folder.
5. Test this file by invoking it from a
URL in a browser. You should get the ‘Connection
successful!’ message.
<?php
require ('../mysqli_connect.php');
//Adjust the path reference to your file organization schema if necessary
?>
You don’t
need to submit anything for this lab. I will just check that your database
tables were created and populated.