Prepared By Roshan Gunathilake (Bsc Computer Science Sp. , SCJP, SCWCD).
Page 1 .... can use to manage, dump ,restore databases with a GUI.
Web Application Development with PHP and MySQL
Prepared By Roshan Gunathilake (Bsc Computer Science Sp. , SCJP, SCWCD)
Page 1
1. PHP is a server side scripting language .PHP scripts are executed on a server. 2. A scripting language is a programming language that allows control of software applications. Script distinct from the core code of application. PHP uses Zend scripting engine. 3. PHP is free and open source software. 4. Advantages of PHP a. Fast b. Inexpensive – FREE c. Customizable – Open Source d. It’s designed to support databases e. Secure 5. MySQL is a database server which supports SQL (Structured Query Language) standards and runs on different platforms. 6. PHP supports many databases such as MySQL, Oracle, etc… But when we use PHP and MySQL together, they have cross platform feature where we can host our application in one O/S and database in another O/S. 7. There are 3 main components which we have to install to work with PHP. They are PHP, Apache HTTP server and MySQL. 8. You can install all 3 components separately and configure them to work together. But the better option is installing an integrated package like WAMP, XAMPP 9. If you configuring 3 components manually, you have to modify these files. a. Php.ini b. Httpd.conf c. My.ini 10. How to test wamp server a. Start->all programs->wamp->start wamp server b. Open your web browser and type http://localhost/ or c. Click on the localhost link from wamp icon in task bar. 11. Services should be restarted after you do any change in configurations 12. How to execute a PHP script, a. Save code with .php extensions b. Save it inside www directory or inside a sub directory. c. If you save it directly inside www, you can’t save it with name index d. If the file name is index (which is inside sub directory) that file will be automatically executed without selecting. 13. In a PHP script, a. PHP code should be enclosed within b. Each statement should end up with ; c. PHP is a case sensitive language d. In PHP, we use $ sign to declare variables 14. Although PHP is said to be a case sensitive language, a. User defined classes and functions are not case sensitive. b. But variable names are case sensitive. 15. Comments are used to give some information to the people who are reading the code, but not for the people who are using the application through a web browser. Prepared By Roshan Gunathilake (Bsc Computer Science Sp. , SCJP, SCWCD)
Page 2
a. Single line comment // b. Multi line comment /* */ 16. Data type is a collection of data elements and associated operators. A variable is a memory location allocated to store data. 17. There are 4 scalar data types in PHP. a. Integer eg:- 1,3 b. Float eg:- 2.5, 4.5 c. String eg:- “abc”, “*” d. Boolean eg:- true, false 18. There are 2 compound data types in PHP a. Arrays b. Objects 19. NULL is a special data type which only has a single value. 20. In PHP, following variables are Boolean false a. NULL values b. Empty String c. Keywords d. Integer 0 e. Array with empty elements f. Objects with no values or functions 21. A variable is considered NULL if, a. It has been assigned the constant NULL b. It has not been set to any values yet. c. It has been unset( ) 22. In PHP, variable doesn’t need to be declared with a data type. They are automatically converted when they are set. 23. Variables and can be classified by it’s scope (visibility) a. Global variables : Visible to whole program b. Local variables: Visible to a particular code block. 24. Static variable exists only in a local function scope, but it doesn’t lose it’s value when program execution leaves this scope. A static variable has only one copy across the program. But an instance variable has many. 25. The value of a constant cannot be changed. a. Syntax : define(“Name”,”Kamal”); 26. A function is a block of code, which is executed whenever it is required to perform a specific action. a. Strlen – Used to find the length of a String b. Strpos – Used to search for a string or a character within a string 27. We cannot use some signs directly inside the double quotations. Therefore we use \ to ignore them. 28. Operators are used to perform arithmetic and logical operations. The operators in PHP can be categorized as follows. a. Arithmetic operators eg:- +,-,*, /, % b. Assignment operators eg :- =, += c. Comparison operator eg:- ==,!=,,= d. Logical operator eg:- AND, &, OR, | Prepared By Roshan Gunathilake (Bsc Computer Science Sp. , SCJP, SCWCD)
Page 3
e. Conditional operator eg:- ? : 29. Control structures are used to control flow of a program. There are 2 types of control structures in PHP. There are 2 types of control structures in PHP. a. Conditional statements: i. If else ii. Switch b. Iteration statements: i. For ii. While iii. Do while iv. Foreach 30. If part of the statement is executed when the condition is true and else part is executed if it is false. 31. Switch statement is used to make a choice or choices among multiple choices. 32. For loop is used to execute a known number of iterations. 33. The body part of the while loop is repeatedly executed until the condition becomes false. 34. Do while loop is similar to while loop, but it guarantees first iteration. 35. Foreach is a modified version of for loop where we can input an array for iteration 36. When a BREAK statement is found, program exits from outer loop. When a CONTINUE statement is found, program moves to the next iteration. 37. An array is a collection of data. Random access is allowed in arrays via index. Index is 0 based. Array index is numeric in a numeric array. 38. A multidimensional array is an array of arrays. 39. Standards in declaring a function. a. All functions should start with the word function. b. Function name must be a valid identifier which is followed by ( ). c. The function code must be inserted within { }. 40. When you install php, a set of builtin functions are installed. User defined functions can contain what ever the instructions we need to execute repeatedly. 41. Parameters are the variables defined within the function header. Arguments are the values passed to the parameters in function calling. 42. There are 3 ways which user can retrieve data from web. a. URL links GET b. Forms POST c. Cookies COOKIE 43. Every language which is used in web development has ways to deal with above 3. 44. We use simple HTML links in PHP. We can retrieve values passed alone HTML links using $_GET in PHP. Except alpha numeric characters, others are converted into % and 2 digit hex code because we cannot pass special characters like +,& directly via URL. 45. HTML encoding can also be used to handle special characters which effects HTML. 46. Form values are passed via the body and they can retrieved with $_POST in PHP. 47. Cookie is a small piece of text stored in user’s computer by a web browser. A cookie consists one or more name value pairs contains information about client. $_COOKIE 48. Session is a time period which the client is active. $_SESSION 49. Headers provide meta information about a web page. Eg : - header (“Location : abc.html”) redirection; Prepared By Roshan Gunathilake (Bsc Computer Science Sp. , SCJP, SCWCD)
Page 4
50. Since PHP5 has improved it’s object oriented programming is based on objects and classes. 51. The advantages of OOP in PHP. a. Improves reusability b. Easier to update c. OOP makes team programming easier d. OOP principals are same regardless of language 52. Disadvantages of OOP in PHP a. Slower in runtime b. Not suitable for small projects 53. Object oriented programming is based on objects and classes. A class is a template to create objects. An object is an instance of a class. 54. 3 steps in OOP are, a. Create classes b. Create objects c. Message passing 55. Principals of OOP, a. Abstraction b. Encapsulation c. Inheritance d. Polymorphism 56. Secure communication is essential to protect sensitive data, including personal information, passed to and from a web application. 57. Security issues to be continued : a. Authentication: Communicating entities verify their identities username/ password combination is normally used. b. Authorization: Interactions with resources are limited to collections of users or programs for the purpose of enforcing integrity. c. Data Integrity: Data integrity proves that information has not been modified by 3 rd party while in transit. d. Confidentiality (Data Privacy) : Ensure that information is made available only to the authorized users. e. Malicious Code : A piece of software that is deliberately designed to harm the computer system. 58. Encryption is the process of changing data into unreadable forms using algorithms. Nd5 and sha1 are popular encryption formats. 59. The MySQL software delivers a very fast, multi threaded, multi usr and robust SQL database server. Some features of MySQL are : a. Written in C and C++ b. Tested with a broad range of compilers c. Works on many different platforms d. APIs for C,C++, Java and PHP are available. e. Fully multi threaded. f. MySQL can handle large databases. 60. Refer MySQL manual for syntaxes of MySQL queries. Phpmyadmin is aMySQL GUI tool which we can use to manage, dump ,restore databases with a GUI. Prepared By Roshan Gunathilake (Bsc Computer Science Sp. , SCJP, SCWCD)
Page 5
61. Steps to connect a MySQL database with a PHP application. a. Create the connection with mysql_connect b. Check the connection with if(!$con) c. Select database with select_db d. Perform query with mysql_query e. Retrieve data with mysql_fetch_array f. Close the connection with mysql_close 62. References a. www.w3schools.com b. PHP User Manual c. MySQL user Manual d. PHP.net e. MySQL.com
Prepared By Roshan Gunathilake (Bsc Computer Science Sp. , SCJP, SCWCD)
Page 6