cs146 database systems &team projects spring 2009

23
CS146 Database Systems &Team Projects Spring 2009

Upload: pierce-conley

Post on 01-Jan-2016

222 views

Category:

Documents


0 download

TRANSCRIPT

Page 1: CS146 Database Systems &Team Projects Spring 2009

CS146 Database Systems &Team

ProjectsSpring 2009

Page 2: CS146 Database Systems &Team Projects Spring 2009

• Lab instructor: – Darby Thompson

[email protected]

• Office Hours: By Appt

• Lab page will be linked from the course page:– http://www.seas.gwu.edu/~bhagiweb/cs146/

Introduction

Page 3: CS146 Database Systems &Team Projects Spring 2009

What do I expect from students in the lab

• WID Writing assignments - go to the WID TA if you have questions

• Programming assignments– Submit using Blackboard– Due at 11.59pm– Don’t be late!

Page 4: CS146 Database Systems &Team Projects Spring 2009

What do I expect from students in the lab

• Grading policy for programming assignments– Queries with syntactic errors will not be

considered. – Run your queries before sending them– If the query works, it is likely you will get all

the points for it

Page 5: CS146 Database Systems &Team Projects Spring 2009

What do I expect from students in the lab

• I will explain everything in the lab. Be there & don’t fall asleep!

• You are expected to play with the tools on your own and learn at least enough to do the project.

• Email me to set up appointments - I’ll probably need more than 1 hour notice!

• Start early…

Page 6: CS146 Database Systems &Team Projects Spring 2009

What do I expect from students in the lab

• Teamwork! You will be working on long term team projects.– Communicate with your teammates and let

them know if you’re having problems– Communicate with me and let me know if

you’re having problems

Page 7: CS146 Database Systems &Team Projects Spring 2009

Lab Outline

• What we will do– SQL, MySQL, etc…– In-class and homework Programming

Assignments– Team Project– PHP, JDBC– Ethics debates/discussions (ideas?)– Lectures/lab swap

Page 8: CS146 Database Systems &Team Projects Spring 2009

Databases

• What do you already know about databases? Keywords? Tools/Applications?

• Any idea what SQL stands for?

Page 9: CS146 Database Systems &Team Projects Spring 2009

Databases

• Standard Query Language

Page 10: CS146 Database Systems &Team Projects Spring 2009

Apply for a mysql account

• Send an email NOW to [email protected] and request a MySQL account. Mention that you are taking CS146

• You will need the account for next lab (in class exercises)

Page 11: CS146 Database Systems &Team Projects Spring 2009

Php

• Official site: www.php.net

• PhP manual: http://www.php.net/manual/en/index.php

• Useful package (Apache, MySql,PhP): http://www.easyphp.org/

Page 13: CS146 Database Systems &Team Projects Spring 2009

How ?

• You can use a basic text editing program to write php files, and CyberDuck to move files onto cobweb

• Additionally can use X11 Terminal to copy a file from your computer to the server using the following command:– scp filename.php

[email protected]:public_html/

Page 14: CS146 Database Systems &Team Projects Spring 2009

What is PhP

• “PHP is a widely-used general-purpose scripting language that is especially suited for Web development and can be embedded into HTML” (www.php.net)

• Server scripting language (Javascript is a client side scripting language)

• If you know C, you will learn PhP in no time.

Page 15: CS146 Database Systems &Team Projects Spring 2009

Hello World!• Index.php:

<html> <head>  <title>PHP Test</title> </head> <body> <?php echo '<p>Hello World</p>'; ?></body></html>

• Output<html>: <head> <title>PHP Test</title> </head> <body> <p>Hello World</p> </body>

</html>

Page 16: CS146 Database Systems &Team Projects Spring 2009

Basics

• Use echo for printing

• Variables start with $ sign

• Do not have to explicitly assign them a type (like int, array, etc.)

• . (dot) concatenates 2 strings. Ex $a=”Hello”;$b=”World”; echo $a.” ”.$b; displays ”Hello World”

Page 17: CS146 Database Systems &Team Projects Spring 2009

Accesing databases from PhP<html> <head>  <title>PHP Test</title> </head> <body><?php$link=mysql_connect("localhost",“username",“password") or die("Error connecting to the database server:".mysql_error()."<br>\n");mysql_select_db(“username") or

die("Error selecting the database:".mysql_error()."<br>\n");?>

<?php$sql = "SELECT name, id FROM employees;";

$result=mysql_query($sql);while(list($name,$id) = mysql_fetch_array($result)){

echo "<p>".$name." ".$id;}?></body></html>

Page 18: CS146 Database Systems &Team Projects Spring 2009

Arrays

• A mapping between keys and values. Example<?php

$arr = array("foo" => "bar", 12 => true);echo $arr["foo"]; // barecho $arr[12];    // 1

foreach ($arr as $key => $value) {

echo “key=”.$key;echo “ value=”,$value.”<BR>”;

}

?>

Page 19: CS146 Database Systems &Team Projects Spring 2009

Get and Post

• $_GET[’variablename’] – the variable is appended to the http address, and is transmited in the same stream. Ex: http://www.somesite.com/index.php?a=1&b=’x’. Easy to bookmark

• $_POST[’variablename’] – a new stream is created, and all the post variables are transmited in this stresm. The http address is clean (no bookmarks)

Page 20: CS146 Database Systems &Team Projects Spring 2009

Get variables from formsgetName.html<HTML><BODY><form action="action.php"

method="post"> <p>Your name: <input type="text"

name="name" /></p> <p>Your age: <input type="text"

name="age" /></p> <p><input type="submit"

value="Submit"/></p> </form> </BODY></HTML>

Action.php<HTML><BODY><?php echo "Your name is ".$_POST["name"]." and you are ".$_POST["age"]." years old";?></BODY></HTML>

Page 21: CS146 Database Systems &Team Projects Spring 2009

Some usefull global variables

• $_SESSION -An associative array containing session variables available to the current script.

• $_SERVER[’PHP_SELF’]- The filename of the currently executing script, relative to the document root. For instance, $_SERVER['PHP_SELF'] in a script at the address http://example.com/test.php/foo.bar would be /test.php/foo.bar.

• $_SERVER['SERVER_NAME']- The name of the server host under which the current script is executing. If the script is running on a virtual host, this will be the value defined for that virtual host.

• __LINE__The current line number of the file.

• __FILE__The full path and filename of the file. If used inside an include, the name of the included file is returned.

Page 22: CS146 Database Systems &Team Projects Spring 2009

Session

• HTTP is stateless

• Simulates a statefull connection. Maintains records on the server side until the browser is closed.

• session_start();

• $_SESSION[‘foo’]=‘bar’;

• $_SESSION[‘a’][‘b’]=‘c’;

• Allows to build a ”shoping cart”;

Page 23: CS146 Database Systems &Team Projects Spring 2009

Includes• header.php• <html>•  <head>•   <title>PHP Test</title>•  </head>•  <body>• <TABLE width="800" cellpadding="4" cellspacing="0" align="center" border="0">• <TR>• <TD width='100%'>

• footer.php• </TD>• </TR>• </TABLE>• </body>• </html>

• index.php• <?php• include ”header.php”;• echo ”hello world”;• include ”footer.php”• ?>