1 / 106

Open Source Programming

Open Source Programming. Topics to be Covered: Open Source Programming PHP Apache MySQL Postgress SQL and PERL Overview of PHP, Variables, Operations, Constants, Control Structures, Arrays, Functions, Classes, Handling Files. Open Source.

ruthb
Télécharger la présentation

Open Source Programming

An Image/Link below is provided (as is) to download presentation Download Policy: Content on the Website is provided to you AS IS for your information and personal use and may not be sold / licensed / shared on other websites without getting consent from its author. Content is provided to you AS IS for your information and personal use only. Download presentation by click this link. While downloading, if for some reason you are not able to download a presentation, the publisher may have deleted the file from their server. During download, if you can't get a presentation, the file might be deleted by the publisher.

E N D

Presentation Transcript


  1. Open Source Programming

  2. Topics to be Covered: Open Source Programming PHP Apache MySQL Postgress SQL and PERL Overview of PHP, Variables, Operations, Constants, Control Structures, Arrays, Functions, Classes, Handling Files.

  3. Open Source Generically, open source refers to a program in which the source code is available to the general public for use and/or modification from its original design free of charge, i.e., open. Open source code is typically created as a collaborative effort in which programmers improve upon the code and share the changes within the community. Open source sprouted in the technological community as a response to proprietary software owned by corporations.

  4. Open Source Software's • PHP • Apache • MySQL • Postgres • Perl

  5. PHP Introduction • The PHP Hypertext Preprocessor (PHP) is a programming language that allows web developers to create dynamic content that interacts with databases. • PHP is basically used for developing web based software applications.  • Originally created by RasmusLerdorf in 1995. • PHP is a recursive acronym for "PHP: Hypertext Preprocessor". • PHP is a server side scripting language that is embedded in HTML. • PHP is free software released under the PHP License. • PHP can be deployed on most web servers and also as on almost every operating system and platform, free of charge.

  6. PHP Introduction (Cont…) • It is used to manage dynamic content, databases, session tracking, even build entire e-commerce sites. • It is integrated with a number of popular databases, including MySQL, PostgreSQL, Oracle, Sybase, Informix, and Microsoft SQL Server. • PHP Syntax is C-Like. • PHP supports a large number of major protocols such as POP3, IMAP, and LDAP. Characteristics of PHP: Simplicity Efficiency Security Flexibility Familiarity

  7. PHP Introduction (Cont…)

  8. Apache Introduction The Apache HTTP Server, commonly referred to as Apache, is a freely available Web server that is distributed under an "open source" license. Apache played a key role in the initial growth of the World Wide Web. Apache is developed and maintained by an open community of developers under the auspices of the Apache Software Foundation.Most commonly used on a Unix-like system, the software is available for a wide variety of operating system including Unix, FreeBSD, Linux, Solaris,  Novell NetWare, OS X, Microsoft Windows, OS/2.

  9. Apache Introduction (Cont…)

  10. MySQL Introduction MySQL :My Sequel is the world's second most widely used open-source relational database management system (RDBMS). The MySQL development project has made its source code available under the terms of the GNU General Public License, as well as under a variety of proprietary agreements. MySQL was owned and sponsored by a single for-profit firm, the Swedish  company MySQL AB , now owned by Oracle Corporation. MySQL is a popular choice of database for use in web applications, and is a central component of the widely used LAMP open source web application software stack . LAMP is an acronym for "Linux , Apache, MySQL, Perl/PHP/Python."  MySQL is also used in many high-profile, large-scale websites, including Wikipedia, Google, Facebook, Twitter, Flickr and YouTube.

  11. MySQL Introduction (Cont…)

  12. Postgres Introduction PostgreSQL is a powerful, open source object-relational database system. It has more than 15 years of active development and a proven architecture that has earned it a strong reputation for reliability, data integrity, and correctness. It can handle workloads ranging from small single-machine applications to large Internet-facing applications with many concurrent users. PostgreSQL runs on all major operating systems, including Linux, UNIX (AIX, BSD, HP-UX, SGI IRIX, Mac OS X, Solaris), and Windows. It is free and open source software, released under the terms of the PostgreSQL License

  13. Postgres Introduction (Cont…) Developers: PostgreSQL Global Development GroupInitial release May 1, 1995Written in COperating system Cross-platform, e.g. most Unix - like OS’s and WindowsType ORDBMSLicense PostgreSQL LicenseWebsite http://www.postgresql.org/

  14. SQL Introduction SQLStructured Query Languageis a special-purpose programming language designed for managing data held in a relational database management system (RDBMS). Originally based upon relational algebra and tuple relational calculus, SQL consists of a data definition language and a data manipulation language. The scope of SQL includes data insert, query, update and delete, schema creation and modification, and data access control. SQL was one of the first commercial languages for Edgar F. Codd's relational model, as described in his influential 1970 paper SQL became a standard of the American National Standards Institute (ANSI) in 1986, and of the International Organization for Standardization (ISO) in 1987.

  15. Perl Introduction • Perl is a programming language developed by Larry Wall, especially designed for text processing. • It stands for Practical Extraction and Report Language. • It runs on a variety of platforms, such as Windows, Mac OS, and the various versions of UNIX. • If you have basic knowledge of C or UNIX Shell then PERL is very easy to learn.

  16. Perl Introduction (Cont…)

  17. PHP Variables • A variable can have a short name or a more descriptive name. • Rules for PHP variables: • A variable starts with the $ sign, followed by the name of the variable. • A variable name must start with a letter or the underscore character. • A variable name cannot start with a number. • A variable name can only contain alpha-numeric characters and underscores (a-z, A-Z 0-9, and _ ). • Variable names are case-sensitive ($age and $AGE are two different variables).

  18. PHP Variables (Cont…) Example: <?php $x = 5; $y = 4;echo $x + $y; ?> PHP is a Loosely Typed Language In the example above, notice that we did not have to tell PHP which data type the variable is. PHP automatically converts the variable to the correct data type, depending on its value. In other languages such as C, C++, and Java, the programmer must declare the name and type of the variable before using it.

  19. PHP Variables (Cont…) PHP Variables Scope In PHP, variables can be declared anywhere in the script. The scope of a variable is the part of the script where the variable can be referenced/used. PHP has three different variable scopes: local global static

  20. PHP Variables (Cont…) A variable declared outside a function has a GLOBAL SCOPE and can only be accessed outside a function. <?php$x = 5; // global scope function myTest() {     // using x inside this function will generate an error    echo "<p>Variable x inside function is: $x</p>"; } myTest(); echo "<p>Variable x outside function is: $x</p>";?>

  21. PHP Variables (Cont…) A variable declared within a function has a LOCAL SCOPE and can only be accessed within that function. <?php function myTest() {$x = 5; // local scope     echo "<p>Variable x inside function is: $x</p>"; } myTest(); // using x outside the function will generate an error echo "<p>Variable x outside function is: $x</p>";?>

  22. PHP Variables (Cont…) Normally, when a function is completed/executed, all of its variables are deleted. However, sometimes we want a local variable NOT to be deleted. We need it for a further job. To do this, use the static keyword when you first declare the variable: <?php function myTest() {     static $x = 0;     echo $x;     $x++; } myTest(); myTest(); myTest();?>

  23. PHP Variables (Cont…) The global keyword is used to access a global variable from within a function. To do this, use the global keyword before the variables (inside the function): Example <?php $x = 5; $y = 10; function myTest() {global $x, $y;     $y = $x + $y; } myTest(); echo $y; // outputs 15 ?>

  24. PHP Data Types • Variables can store data of different types, and different data types can do different things. • PHP supports the following data types: • String • Integer • Float • Boolean • Array • Object • NULL • Resource

  25. PHP Data types (Cont…) A string is a sequence of characters, like "Hello world!". A string can be any text inside quotes. You can use single or double quotes: Example: <?php $x = "Hello world!"; $y = 'Hello world!'; echo $x; echo "<br>"; echo $y; ?>

  26. PHP Data types (Cont…) The following functions can be applied on strings: echo strlen("Hello world!"); // outputs 12 echo str_word_count("Hello world!"); // outputs 2 echo strrev("Hello world!"); // outputs !dlrow olleH echo strpos("Hello world!", "world"); // outputs 6 echo str_replace("world", "Dolly", "Hello world!"); // outputs Hello Dolly!

  27. PHP Data types (Cont…) • Integer: • An integer is a whole number (without decimals).  • Rules for integers: • An integer must have at least one digit (0-9) . • An integer cannot contain comma or blanks. • An integer must not have a decimal point. • An integer can be either positive or negative. • In the following example $x is an integer. • The PHP var_dump() function returns the data type and value. • <?php $x = 100; var_dump($x); ?>

  28. PHP Data types (Cont…) Float: A float (floating point number) is a number with a decimal point or a number in exponential form. In the following example $x is a float. The PHP var_dump() function returns the data type and value. Example: <?php $x = 10.365; var_dump($x); ?>

  29. PHP Data types (Cont…) Boolean: A Boolean represents two possible states: TRUE or FALSE. $x = true; $y = false; Booleans are often used in conditional testing. PHP Array: An array stores multiple values in one single variable. In the following example $cars is an array. The PHP var_dump() function returns the data type and value. Example: <?php $cars = array("Volvo","BMW","Toyota"); var_dump($cars); ?>

  30. PHP Data types (Cont…) NULL Value: Null is a special data type which can have only one value: NULL. A variable of data type NULL is a variable that has no value assigned to it. Tip: If a variable is created without a value, it is automatically assigned a value of NULL. Variables can also be emptied by setting the value to NULL: Example: <?php $x = "Hello world!"; $x = null; var_dump($x); ?>

  31. Operators • Operators are used to perform operations on variables and values. • PHP language supports following type of operators: • Arithmetic operators • Assignment operators • Comparison operators • Increment/Decrement operators • Logical operators • String operators • Array operators

  32. Arithmetic Operators • The PHP arithmetic operators are used with numeric values to • perform common arithmetical operations. Operators (Cont…)

  33. Operators (Cont…) • Assignment Operators • The PHP assignment operators are used with numeric values to • write a value to a variable. • The basic assignment operator in PHP is "=". It means that the left • operand gets set to the value of the assignment expression on the • right.

  34. Operators (Cont…) • Comparison Operators • The PHP comparison operators are used to compare two values • (number or string).

  35. Operators (Cont…) Example 1: <?php $x = 100; $y = "100"; var_dump($x = = = $y); // returns false because types are not equal?>  Example 2: <?php $x = 100; $y = "100"; var_dump($x != = $y); // returns true because types are not equal?>  

  36. Operators (Cont…) • Increment / Decrement Operators • The PHP increment operators are used to increment a variable's • value. • The PHP decrement operators are used to decrement a variable's • value.

  37. Operators (Cont…) • Logical Operators • The PHP logical operators are used to combine conditional • statements.

  38. Operators (Cont…) • String Operators • PHP has two operators that are specially designed for strings.

  39. Operators (Cont…) • Array Operators • The PHP array operators are used to compare arrays.

  40. Operators (Cont…) Example 1: <?php $x = array("a" => "red", "b" => "green"); $y = array("c" => "blue", "d" => "yellow"); var_dump($x == $y);?>   Example 2: <?php $x = array("a" => "red", "b" => "green"); $y = array("c" => "blue", "d" => "yellow"); var_dump($x === $y);?>     Example 3: <?php $x = array("a" => "red", "b" => "green"); $y = array("c" => "blue", "d" => "yellow"); print_r($x + $y); // union of $x and $y?>   

  41. Constants A constant is an identifier (name) for a simple value. The value cannot be changed during the script. A valid constant name starts with a letter or underscore (no $ sign before the constant name). Unlike variables, constants are automatically global across the entire script. By default a constant is case-sensitive. To define a constant, use define() function and to retrieve the value of a constant, you have to simply specifying its name. The function constant() is used to read a constant's value if you wish to obtain the constant's name dynamically.

  42. Constants (Cont…) Creating a constant: To create a constant, use the define() function. define (name, value, case-insensitive); Parameters: name: Specifies the name of the constant. value: Specifies the value of the constant. case-insensitive: Specifies whether the constant name should be case-insensitive. Default is false.

  43. Constants (Cont…) The example below creates a constant with a case-sensitive name: <?phpdefine("GREETING", "Welcome to PHP!"); echo GREETING;?> The example below creates a constant with a case-insensitive name: <?phpdefine("GREETING", " Welcome to PHP!", true); echo greeting;?>

  44. Constants (Cont…) constant() function: As indicated by the name, this function will return the value of the constant. <?php define("MINSIZE", 50); echo MINSIZE; echo constant("MINSIZE"); // same thing as the previous line ?>

  45. Constants (Cont…) Constants are Global: Constants are automatically global and can be used across the entire script. The example below uses a constant inside a function, even if it is defined outside the function. <?phpdefine ("GREETING", "Welcome to PHP!"); function myTest() { echo GREETING; }  myTest();?>

  46. Constants (Cont…) Differences between constants and variables are: There is no need to write a dollar sign ($) before a constant, where as in variable one has to write a dollar sign. Constants cannot be defined by simple assignment, they may only be defined using the define() function. Constants may be defined and accessed anywhere without regard to variable scoping rules. Once the Constants have been set, may not be redefined or undefined.

  47. Control Structures • Conditional statements are used to perform different actions based • on different conditions. • Conditional Statements • In PHP we have the following conditional statements: • if statement - executes some code only if a specified condition is • true. • if...else statement - executes some code if a condition is true and • another code if the condition is false. • if...elseif....else statement - specifies a new condition to test, if the • first condition is false. • switch statement - selects one of many blocks of code to be • executed.

  48. Control Structures (Cont…) • The if Statement • The if statement is used to execute some code only if a specified • condition is true. • if (condition) {     code to be executed if condition is true; } • The if...else Statement • Use the if....else statement to execute some code if a condition is • true and another code if the condition is false. • if (condition) {code to be executed if condition is true; } else • {  code to be executed if condition is false;}

  49. Control Structures (Cont…) • The if...elseif....else Statement • Use the if....elseif...else statement to specify a new condition to test, • if the first condition is false. • if (condition) {code to be executed if condition is true;} • elseif (condition) • {  code to be executed if condition is true;} • else • {code to be executed if condition is false;}

  50. Control Structures (Cont…) • switch Statement • The switch statement is used to perform different actions based on • different conditions. • Use the switch statement to select one of many blocks of code to be • executed. • switch (n) {caselabel1:      code to be executed if n=label1;break;caselabel2:      code to be executed if n=label2;break;     case label3:      code to be executed if n=label3;break;     ...default:      code to be executed if n is different from all labels; }

More Related