Presentation is loading. Please wait.

Presentation is loading. Please wait.

PHP is a server scripting language, and a powerful tool for making dynamic and interactive Web pages. PHP is a widely-used, free, and efficient alternative.

Similar presentations


Presentation on theme: "PHP is a server scripting language, and a powerful tool for making dynamic and interactive Web pages. PHP is a widely-used, free, and efficient alternative."— Presentation transcript:

1

2 PHP is a server scripting language, and a powerful tool for making dynamic and interactive Web pages. PHP is a widely-used, free, and efficient alternative to competitors such as Microsoft's ASP.

3 What is PHP? PHP is an acronym for "PHP: Hypertext Preprocessor" PHP is a widely-used, open source scripting language PHP scripts are executed on the server PHP is free to download and use It is powerful enough to be at the core of the biggest blogging system on the web (WordPress)! It is deep enough to run the largest social network (Facebook)! It is also easy enough to be a beginner's first server side language!

4 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" What Can PHP Do? PHP can generate dynamic page content PHP can create, open, read, write, delete, and close files on the server PHP can collect form data PHP can send and receive cookies PHP can add, delete, modify data in your database PHP can be used to control user-access PHP can encrypt data With PHP you are not limited to output HTML. You can output images, PDF files, and even Flash movies. You can also output any text, such as XHTML and XML.

5 Why PHP? PHP runs on various platforms (Windows, Linux, Unix, Mac OS X, etc.) PHP is compatible with almost all servers used today (Apache, IIS, etc.) PHP supports a wide range of databases PHP is free. Download it from the official PHP resource: www.php.netwww.php.net PHP is easy to learn and runs efficiently on the server side

6 Basic PHP Syntax A PHP script can be placed anywhere in the document. A PHP script starts with : A PHP file normally contains HTML tags, and some PHP scripting code. Note: PHP statements end with a semicolon (;).

7 PHP MySQL Database With PHP, you can connect to and manipulate databases. MySQL is the most popular database system used with PHP. What is MySQL? MySQL is a database system used on the web MySQL is a database system that runs on a server MySQL is ideal for both small and large applications MySQL is very fast, reliable, and easy to use MySQL uses standard SQL MySQL compiles on a number of platforms MySQL is free to download and use MySQL is developed, distributed, and supported by Oracle Corporation MySQL is named after co-founder Monty Widenius's daughter: My

8 PHP Connect to MySQL PHP 5 and later can work with a MySQL database using: 1-MySQLi extension (the "i" stands for improved) 2-PDO (PHP Data Objects)

9 Should I Use MySQLi or PDO? "Whatever you like". Both MySQLi and PDO have their advantages: PDO will work on 12 different database systems, where as MySQLi will only work with MySQL databases. So, if you have to switch your project to use another database, PDO makes the process easy. You only have to change the connection string and a few queries. With MySQLi, you will need to rewrite the entire code - queries included. Both are object-oriented, but MySQLi also offers a procedural API. Both support Prepared Statements. Prepared Statements protect from SQL injection, and are very important for web application security.

10 Open a Connection to MySQL Before we can access data in the MySQL database, we need to be able to connect to the server: Example (MySQLi Object-Oriented) <?php $servername = "localhost"; $username = "username"; $password = "password"; // Create connection $conn = new mysqli($servername, $username, $password); // Check connection if ($conn->connect_error) { die("Connection failed: ". $conn->connect_error); } echo "Connected successfully"; ?>

11 Example (MySQLi Procedural)

12 Close the Connection The connection will be closed automatically when the script ends. To close the connection before, use the following: Example (MySQLi Object-Oriented) $conn->close(); Example (MySQLi Procedural) mysqli_close($conn);

13 References http://www.w3schools.com/php/php_mysql_connect.asp http://www.w3schools.com/php/php_mysql_intro.asp http://www.w3schools.com/php/php_intro.asp http://php.net/


Download ppt "PHP is a server scripting language, and a powerful tool for making dynamic and interactive Web pages. PHP is a widely-used, free, and efficient alternative."

Similar presentations


Ads by Google