Everyday Italian Giada De Laurentiis 2005 30.00 Harry Potter J K. Rowling 2005 29.99 Learning XML Erik T. Ray 2003 39.95 CSCI 305 Introduction to Database.

Slides:



Advertisements
Similar presentations
PHP I.
Advertisements

JavaScript I. JavaScript is an object oriented programming language used to add interactivity to web pages. Different from Java, even though bears some.
+ Intro to PHP and SQL James Ohene-Djan. + What We’ll Cover Introduction to PHP Explain example code Introduction to Database Using PHP/MySQL for database.
Introduction to PHP MIS 3501, Fall 2014 Jeremy Shafer
Introduction to Database
 2008 Pearson Education, Inc. All rights reserved JavaScript: Introduction to Scripting.
Website Development Introducing PHP The PHP scripting language Syntax derives from C, Java and Perl Open Source Links to MySql database.
PHP Server-side Programming. PHP  PHP stands for PHP: Hypertext Preprocessor  PHP is interpreted  PHP code is embedded into HTML code  interpreter.
Types of websites (PHP basics). Website  A website, also written Web site, web site, or simply site, is a collection of related web pages containing.
 2004 Prentice Hall, Inc. All rights reserved. Chapter 25 – Perl and CGI (Common Gateway Interface) Outline 25.1 Introduction 25.2 Perl 25.3 String Processing.
PHP The Basic. Outline  History of PHP  What is PHP?  What does PHP code look like?  Apache Server.  Syntax PHP code.  Anatomy of a PHP Script.
PHP: Introduction By Trevor Adams.
Introduction to PHP. PHP PHP is the Hypertext Pre-processor –Script language –Embedded into HTML –Runs as Apache module –Can use DB (MySQL, Oracle, Microsoft.
PHP Overview CS PHP PHP = PHP: Hypertext Preprocessor Server-side scripting language that may be embedded into HTML One goal is to get PHP files.
PHP Tutorials 02 Olarik Surinta Management Information System Faculty of Informatics.
PHP == ‘ Hypertext Preprocessor ’ Open-source, server-side scripting language Used to generate dynamic web-pages PHP scripts reside between reserved PHP.
Programming with php By: Seth Larson. A little bit about PHP  PHP stands for PHP:  Hypertext Preprocessor  PHP is a widely-used general-purpose server-side.
Application Development Description and exemplification of server-side scripting language for server connection, database selection, execution of SQL queries.
Introduction to PHP and Server Side Technology. Slide 2 PHP History Created in 1995 PHP 5.0 is the current version It’s been around since 2004.
PHP Forms and User Input The PHP $_GET and $_POST variables are used to retrieve information from forms, like user input.
INTERNET APPLICATION DEVELOPMENT For More visit:
Introduction to Database. What is PHP? PHP == ‘PHP Hypertext Preprocessor’ Open-source, server-side scripting language Used to generate dynamic web-pages.
PHP H ypertext P re-processor. Unit 6 - PHP - Hello World! - Data types - Control structures - Operators.
MySQL in PHP – Page 1 of 17CSCI 2910 – Client/Server-Side Programming CSCI 2910 Client/Server-Side Programming Topic: MySQL in PHP Reading: Williams &
NMED 3850 A Advanced Online Design January 26, 2010 V. Mahadevan.
School of Computing and Information Systems CS 371 Web Application Programming PHP - Basics Serving up web pages.
November 2003Bent Thomsen - FIT 6-11 IT – som værktøj Bent Thomsen Institut for Datalogi Aalborg Universitet.
PHP MySQL Introduction. MySQL is the most popular open-source database system. What is MySQL? MySQL is a database. The data in MySQL is stored in database.
Creating Dynamic Web Pages Using PHP and MySQL CS 320.
PHP - Basic Language Constructs CSCI 297 Scripting Languages - Day Two.
PHP+MySQL Integration. Connecting to databases One of the most common tasks when working with dynamic webpages is connecting to a database which holds.
Web-Based Database Programming with PHP. Dept. of Computing Science, University of Aberdeen2 In this lecture you will learn PHP Basics PHP functions –To.
PHP. What is PHP? PHP stands for PHP: Hypertext Preprocessor PHP is a server-side scripting language, like ASP PHP scripts are executed on the server.
PHP PHP: Hypertext Preprocesor Personal Home Page Tools.
Just a Little PHP Programming PHP on the Server. Common Programming Language Features Comments Data Types Variable Declarations Expressions Flow of Control.
1Computer Sciences Department Princess Nourah bint Abdulrahman University.
Fall 2004CSI University of Ottawa Introduction to PHP Basic principles and syntax.
Web Technology Introduction to PHP. PHP PHP stands for PHP Hypertext Preprocessor PHP is a Server-Side Web Scripting language, which executes on the web.
CSE 154 LECTURE 5: INTRO TO PHP. URLs and web servers usually when you type a URL in your browser: your computer looks up the.
JavaScript Scripting language What is Scripting ? A scripting language, script language, or extension language is a programming language.
Introduction to PHP.
הרצאה 4. עיבוד של דף אינטרנט דינמי מתוך Murach’s PHP and MySQL by Joel Murach and Ray Harris.  דף אינטרנט דינמי משתנה עפ " י הרצת קוד על השרת, יכול להשתנות.
IT ELECTIVE 2.  Web server Can refer to either the hardware (the computer) or the software (the computer application) that helps to deliver content that.
 2008 Pearson Education, Inc. All rights reserved JavaScript: Introduction to Scripting.
Fall 2004CSI University of Ottawa Introduction to PHP Basic principles and syntax.
8 th Semester, Batch 2009 Department Of Computer Science SSUET.
PHP/MySQL Tutorial Introduction to Database Programming.
Copyright © 2011 Pearson Education, Inc. Publishing as Pearson Addison-Wesley Chapter 14 Web Database Programming Using PHP.
1 PHP Intro PHP Introduction After this lecture, you should be able to: Know the fundamental concepts of Web Scripting Languages in general, PHP in particular.
Dr. Abdullah Almutairi Spring PHP is a server scripting language, and a powerful tool for making dynamic and interactive Web pages. PHP is a widely-used,
1 Server Side scripting PHP. 2 What is PHP? PHP stands for PHP: Hypertext Preprocessor PHP is a server-side scripting language, like ASP PHP scripts are.
A pache M ySQL P hp Robert Mudge Reference:
PHP using MySQL Database for Web Development (part II)
Web Database Programming Using PHP
CHAPTER 5 SERVER SIDE SCRIPTING
PHP Introduction.
PHP and MySQL.
PHP.
PHP.
Web DB Programming: PHP
Basics.
HYPERTEXT PREPROCESSOR BY : UMA KAKKAR
Web Programming Language
Tutorial 6 PHP & MySQL Li Xu
Tutorial 10: Programming with javascript
PHP an introduction.
PHP-II.
SEEM 4540 Tutorial 4 Basic PHP based on w3Schools
Presentation transcript:

Everyday Italian Giada De Laurentiis Harry Potter J K. Rowling Learning XML Erik T. Ray CSCI 305 Introduction to Database Systems Professor Brian R. King Bucknell University – Computer Science Dept. PHP SELECT * FROM Students WHERE Grade >= 90 XML

Objective This is designed to teach you some bare essentials about PHP, and using it to connect to your DB

PHP Basics PHP – Hypertext Preprocessor Server-side scripting language Scripts reside between reserved PHP tags – Programmer can embed PHP in the HTML pages – Structurally similar to C/C++/Java syntax

PHP Basics Comments: – // –#–# – /* */ Variables: – All variables begin with $ – Case sensitive Type: – PHP is loosely typed. You do not need to declare variables before you add a value to it. PHP determines the type, depending on its initial value

PHP echo command echo is used to output the parameters passed to it Typical usage – send data to the client's web- browser

Echo example Notice how echo ‘5x5=$foo’ outputs $foo rather than replacing it with 25 Strings in single quotes (‘ ’) are not interpreted or evaluated by PHP This is true for both variables and character escape-sequences (such as “\n” or “\\”) <?php $foo = 25;// Numerical variable $bar = “Hello”;// String variable echo $bar;// Outputs Hello echo $foo,$bar;// Outputs 25Hello echo “5x5=”,$foo;// Outputs 5x5=25 echo “5x5=$foo”;// Outputs 5x5=25 echo ‘5x5=$foo’;// Outputs 5x5=$foo ?> <?php $foo = 25;// Numerical variable $bar = “Hello”;// String variable echo $bar;// Outputs Hello echo $foo,$bar;// Outputs 25Hello echo “5x5=”,$foo;// Outputs 5x5=25 echo “5x5=$foo”;// Outputs 5x5=25 echo ‘5x5=$foo’;// Outputs 5x5=$foo ?>

Arithmetic Operations $a - $b // subtraction $a * $b// multiplication $a / $b// division $a += 5// $a = $a+5 Also works for *= and /= <?php $a=15; $b=30; $total=$a+$b; echo $total; echo “ $total ”; // total is 45 ?> <?php $a=15; $b=30; $total=$a+$b; echo $total; echo “ $total ”; // total is 45 ?>

Concatenation Use a period to join strings into one. <?php $string1=“Hello”; $string2=“PHP”; $string3=$string1. “ ”. $string2; echo $string3; ?> <?php $string1=“Hello”; $string2=“PHP”; $string3=$string1. “ ”. $string2; echo $string3; ?> Hello PHP

Escaping the Character If the string has a set of double quotation marks that must remain visible, use the \ [backslash] before the quotation marks to ignore and display them. <?php $heading="\"Computer Science\""; echo $heading; ?> <?php $heading="\"Computer Science\""; echo $heading; ?> “Computer Science”

Control Structures if / else if / else while / do..while / for – foreach exists, but syntax is different switch / case / break / default boolean expressions All of the above are formed just like Java (same comparison and logical operators)

Arrays Three types: – Numeric array – An array with a numeric index – Associative array – Each ID key is associated with a value – Multidimensional array Dealing with arrays is easy. However, the library of functions for arrays is large.

Functions Functions MUST be defined before then can be called Function headers are of the format – Note that no return type is specified Unlike variables, function names are not case sensitive (foo(…) == Foo(…) == FoO(…)) function functionName($arg_1, $arg_2, …, $arg_n)

Functions example <?php // This is a function function foo($arg_1, $arg_2) { $arg_2 = $arg_1 * $arg_2; return $arg_2; } $result_1 = foo(12, 3);// Store the function echo $result_1;// Outputs 36 echo foo(12, 3);// Outputs 36 ?> <?php // This is a function function foo($arg_1, $arg_2) { $arg_2 = $arg_1 * $arg_2; return $arg_2; } $result_1 = foo(12, 3);// Store the function echo $result_1;// Outputs 36 echo foo(12, 3);// Outputs 36 ?>

Include Files include "opendb.php"; include "closedb.php"; The code in files will be inserted into current code. – Nice for modularizing and reusability

PHP Forms and User Input PHP $_GET and $_POST variables are used to retrieve information from forms, like user input NOTE: Any form element in an HTML page will automatically be available to your PHP scripts

Example form welcome.php

form.php <?php if ($_POST["submit"]) echo " You clicked Submit! "; else if ($_POST["cancel"]) echo " You clicked Cancel! "; ?> <?php if ($_POST["submit"]) echo " You clicked Submit! "; else if ($_POST["cancel"]) echo " You clicked Cancel! "; ?> What you see on your browser after clicking Submit

MySQL connection Best way is to just show by example…

connect.php <?php $user = "brk009"; $password = "……"; $database = "brk009_WWIIShipsDB"; $conn = mysql_connect("db.eg.bucknell.edu",$user,$password); if (!$conn) die("Cound not connect to database"); mysql_select_db($database) or die("Unable to select database"); $result = mysql_query("SHOW TABLES"); if (!$result) die("Query to show tables failed"); <?php $user = "brk009"; $password = "……"; $database = "brk009_WWIIShipsDB"; $conn = mysql_connect("db.eg.bucknell.edu",$user,$password); if (!$conn) die("Cound not connect to database"); mysql_select_db($database) or die("Unable to select database"); $result = mysql_query("SHOW TABLES"); if (!$result) die("Query to show tables failed");

connect.php (cont.) $num_row = mysql_num_rows($result); echo " Choose one table: "; echo " "; for($i = 0; $i < $num_row; $i++) { $tablename = mysql_fetch_row($result); echo " {$tablename[0]} "; } echo " "; mysql_free_result($result); mysql_close($conn); ?> $num_row = mysql_num_rows($result); echo " Choose one table: "; echo " "; for($i = 0; $i < $num_row; $i++) { $tablename = mysql_fetch_row($result); echo " {$tablename[0]} "; } echo " "; mysql_free_result($result); mysql_close($conn); ?>

showtable.php <?php $user = "brk009"; $password = "……"; $database = "brk009_WWIIShipsDB"; $table = $_POST["table"]; $conn = mysql_connect("db.eg.bucknell.edu",$user,$password); if (!$conn) die("Cound not connect to database"); mysql_select_db($database) or die("Unable to select database"); $result = mysql_query("SELECT * FROM {$table}"); if (!$result) die("Query to show tuples from table failed!". mysql_error()); <?php $user = "brk009"; $password = "……"; $database = "brk009_WWIIShipsDB"; $table = $_POST["table"]; $conn = mysql_connect("db.eg.bucknell.edu",$user,$password); if (!$conn) die("Cound not connect to database"); mysql_select_db($database) or die("Unable to select database"); $result = mysql_query("SELECT * FROM {$table}"); if (!$result) die("Query to show tuples from table failed!". mysql_error());

showtable.php (cont.) $fields_num = mysql_num_fields($result); echo " Table: {$table} "; echo " "; // Print headers for($i = 0; $i < $fields_num; $i++) { $field = mysql_fetch_field($result); echo " {$field->name} "; } echo " \n"; // Print data while($row = mysql_fetch_row($result)) { echo " "; foreach($row as $cell) echo " $cell "; echo " \n"; } mysql_free_result($result); mysql_close($conn); ?> $fields_num = mysql_num_fields($result); echo " Table: {$table} "; echo " "; // Print headers for($i = 0; $i < $fields_num; $i++) { $field = mysql_fetch_field($result); echo " {$field->name} "; } echo " \n"; // Print data while($row = mysql_fetch_row($result)) { echo " "; foreach($row as $cell) echo " $cell "; echo " \n"; } mysql_free_result($result); mysql_close($conn); ?>