Presentation is loading. Please wait.

Presentation is loading. Please wait.

Tutorial 6 PHP & MySQL Li Xu

Similar presentations


Presentation on theme: "Tutorial 6 PHP & MySQL Li Xu"— Presentation transcript:

1 Tutorial 6 PHP & MySQL Li Xu
Department of Systems Engineering and Engineering Management

2 Outline PHP: Hypertext Preprocessor PHP Introduction PHP Syntax
PHP Variables PHP Functions MySQL Database MySQL Introduction MySQL Connect MySQL Create DB MySQL Operations

3 PHP Introduction What is PHP? What is a PHP File?
an acronym for “PHP: Hypertext Preprocessor” a widely-used, open source scripting language PHP scripts are executed on the server free to download and use What is a PHP File? PHP files can contain text, HTML, CSS, JavaScript, and PHP code PHP code are executed on the server, and the result is returned to the browser as plain HTML PHP files have extension ".php"

4 PHP Introduction What can PHP do? Why PHP?
generate dynamic page content create, open, read, write, delete, and close files on the server collect form data send and receive cookies add, delete, modify data in your database be used to control user-access encrypt data Why PHP? run on various platforms (Windows, Linux, Unix, etc.) compatible with almost all servers used today (Apache, IIS, etc.) supports a wide range of databases

5 PHP Syntax Basic PHP Syntax Comments in PHP
A PHP script can be placed anywhere in the docment, and starts with ‘<?php’ and ends with ‘?>’ The default file extension for PHP files is “.php” Comments in PHP

6 PHP Syntax PHP Case Sensitivity
In PHP, all keywords (e.g. if, else, while, echo, etc.), classes, functions, and user-defined functions are NOT case-sensitive. However, all variable names are case-sensitive

7 PHP Variables Creating (Declaring) PHP Variables
In PHP, a variable starts with the $ sign, followed by the name of the variable: PHP has no command for declaring a variable, it is created the moment you first assign a value to it. A variable name must start with a letter or the underscore character, cannot start with a number. A variable name can only contain alpha-numeric characters and underscores (A-z, 0-9, and _ ) Variable names are case-sensitive ($age and $AGE are two different variables)

8 PHP Variables Output Variables PHP is a loosely typed language
The PHP echo statement is often used to output data to the screen: PHP is a loosely typed language PHP automatically converts the variable to the correct data type, depending on its value

9 PHP Functions Create a user defined function in PHP
A user-defined function declaration starts with the word function: PHP function arguments Arguments are specified after the function name, inside the parentheses. You can add as many arguments as you want, just separate them with a comma.

10 PHP Functions PHP default argument value Returning values

11 MySQL Introduction What is MySQL? Download MySQL Database
a database system used on the web, runs on a server ideal for both small and large applications fast, reliable, and easy to use use standard SQL complies on a number of platforms free to download and use Download MySQL Database If you don’t have a PHP server with a MySQL Database, you can download it for free via

12 MySQL Connect PHP connect to MySQL Open a connection to MySQL
MySQLi Object-Oriented PHP connect to MySQL PHP 5 and later can work with a MySQL database using: MySQLi extension (the “i” stands for imporved): PDO (PHP Data Objects) Open a connection to MySQL Before we can access data in the MySQL database, we need to be able to connect to the server PDO

13 MySQL Connect PHP connect to MySQL Close the connection
MySQLi Object-Oriented: $conn->close(); PDO: $conn = null;

14 MySQL Create DB A database consists of one or more tables, you can use special CREATE privileges to create a MySQL database: Create a MySQL Database using MySQLi Create a MySQL Database using PDO

15 MySQL Operations (SQL)
Create a table: Insert data: Select data: select data from one or more tables: SELECT column_name(s) FROM table_name select all columns from a table: SELECT * FROM table_name

16 MySQL Operations (SQL)
Delete data from MySQL: e.g.: delete from MyGuests where id=3 Update data: e.g.: update MyGuests set lastname=‘Doe’ where id=2

17 Resources PHP: https://www.w3schools.com/php/default.asp MySQL:

18 Questions and Answers


Download ppt "Tutorial 6 PHP & MySQL Li Xu"

Similar presentations


Ads by Google