|
|
|
|||||||
|
||||||||
|
|
|
|||||||
MySQL Setup for CSCI 244201 - The mysql service should have been included in the initial setup of XAMPP. Start PortableApps and run the setup_xampp.bat file if you need to change the drive letters. Next start xampp_start button inside PortableApps. Verify mysql is running by pressing Ctrl+Alt+Del and select Task Master. Under processes, click the Image Name column to organize all images alphabetically then scroll to the M section and verify you see a service called mysqld.exe running. If you do not see this, you will need to check the xampp documentation and reinstall/reconfigure mysql. Note: Apache.exe should also appear in this listing. This is the service which allows php files to be executed correctly. 02 - The tool used to configure and run mysql is called phpMyAdmin. Copy the directory called phpMyAdmin from the xampp directory to the htdocs directory. This will allow you to run the tool through a web browser interface. Verify you copied it correctly by entering "http://localhost/phpMyAdmin" into your browser. For now, ignore the security message at the bottom of the page. This will be addresses later on on the tutorial. From this page, databases are created and managed via a browser interface. In the "Create New Database" textbox, type in "addressbook" and keep the deault selection of "Collation", then click Create. On the next page, under "Create new table on database addressbook" enter "person" as the name and "5" as the number of fields, then click Go. On the next page, enter the following information: Field Type Length ------------------------------ id INT 11 firstName VARCHAR 20 lastName VARCHAR 20 phone VARCHAR 10 email VARCHAR 40 In addition, for the id row ONLY, select "auto_increment" under Extra and select the "Primary Key" radio button. Click the Save button at this point.
03 - At this point, a table called person has been created in a database called addressbook which
resides on the server called localhost. This should be displayed at the top of the screen on the
right hand side. Click the Home icon on the left side of the screen to return to the main phpMyAdmin page.
From here, click on addressbook on the left side, then click the person table and you will have
returned to the page you saw at the start of step 3. To populate the database, click the Insert tab on
the left side. Do not enter any information for the function pulldown box and also keep the value
entry for id blank as well. For firstName, lastName, phone and email, enter the following information
in the Value fields: 04 - Click the Insert tab again and repeat the procedure four more times, entering the following information: firstName lastName phone email ------------------------------------------------------------ John Johnson 6515552000 jjohnson@companyx.com Bob Williams 6515553000 bwilliams@companyx.com Rick Davis 6515554000 rdavis@companyx.com Dave Brown 6515555000 dbrown@companyx.com Make sure to keep the id value field blank each time. Once you're done, click the Browse tab to display the five entries. 05 - Inside the htdocs directory, create a folder called mysqltest1. Inside this directory, create a file called index.php and insert the following lines:
<html>
<head>
<title>MySQL Test 1</title>
</head>
<body>
<h1>Mysql Test 1</h1>
<?php
$connect_status = mysql_connect('localhost', 'root', '');
$database_status = mysql_select_db('addressbook', $connect_status);
$query = "SELECT * FROM person";
$result = mysql_query($query);
$total_rows = mysql_num_rows($result);
print "Total number of data records: $total_rows<br /><br />";
$row = mysql_fetch_array($result);
print "The value of row[0] is $row[0]<br />";
print "The value of row[1] is $row[1]<br />";
print "The value of row[2] is $row[2]<br />";
print "The value of row[3] is $row[3]<br />";
print "The value of row[4] is $row[4]<br /><br />";
mysql_close($connect_status);
?>
</body>
</html>
For now, do not worry about the mysql syntax. It will be covered later. Save and close the document, then open your browser to http://localhost/mysqltest1. You should see the first entry of the database. Show the results to the instructor. 06 - Return to the index.php file inside mysqltest1 and copy the following lines: $row = mysql_fetch_array($result); print "The value of row[0] is $row[0]<br />"; print "The value of row[1] is $row[1]<br />"; print "The value of row[2] is $row[2]<br />"; print "The value of row[3] is $row[3]<br />"; print "The value of row[4] is $row[4]<br /><br />"; Paste the results four times just above the myqsl_close statement. Save the file and view the results. Verify all five fields display as expected. 07 - The default xampp installation does NOT have a password set for the mysql databases. To
improve security, go to http://localhost/security/ and select English. Click the link at the bottom
of the page for http://localhost/security/xamppsecurity.php, then enter "qwerty" as the new password
and confirm it. Keep the cookie radio button selected and place a check next to "Plain password in text
file" and click Password changing. Before restarting the xampp service, you'll need to make two changes.
First, go to the index.php file inside the mysqltest1 directory and change this line: Second, navigate to the htdocs/phpMyAdmin directory and open the file called config.inc.php with
Notepad. Change this line: Once this is done, close all browsers and window editors, the click the xampp_stop icon from the PortableApps menu. Click xampp_start to restart PortableApps then start your browser and enter the URL http://localhost/mysqltest1/ and verify you see the same results from step 6. Next, enter http://localhost/phpMyAdmin/ in your browser. Select the addressbook database, then the person table. Click the insert button and enter one more entry: firstName: Fred lastName: Anderson phone: 6515556000 email: fanderson@companyx.com 08 - Return to the index.php file in mysqltest1, then copy and paste one more set of the lines used in step 6, right above the mysql_close statement. Save the results and verify the new entry is displayed when you enter http://localhost/mysqltest1/ BACK |
||||||||