BY
M.LAVANYA,M.SC(CS)
NADAR SARASWATHI COLLEGE
OF ARTS AND SCIENCE ,THENI.
 PHP == ‘HYPERTEXT PREPROCESSOR’
 open-source, server-side scripting language
 Used to generate dynamic web-pages
 PHP scripts reside between reserved PHP tags
• This allows the programmer to embed PHP scripts within HTML
pages
 Interpreted language, scripts are parsed at run-time
rather than compiled beforehand
 Executed on the server-side
 Source-code not visible by client
• ‘view source’ in browsers does not display the PHP code
 Various built-in functions allow for fast development
 Compatible with many popular databases
 PHP is a general-purpose server-side scripting language
originally designed for web development to produce
dynamic web pages .
 PHP can interact with My SQL databases.
 Structurally similar to C/C++
 Support procedural and object-oriented paradigm (to
some degree)
 All PHP statements end with a semi-colon
 Each PHP script must be enclosed in the reserved PHP
tag
<?php
……
?>
 Standard C, C++, and shell comment symbols.
//C++ and java-style comment
# shell-style comments
/* C-style comments
These can span multiple lines*/
 PHP variables must begin with a “$” sign.
 Case-sensitive
 Global and locally-scoped variables.
• global variables can be used anywhere
• local variables restricted to a function or class
 Certain variable names reserved by PHP
• form variables ($_POST, $_GET)
• server variables($_ SERVER)
 Etc.
• 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
• The data in a MySQL database are stored in tables. A
table is a collection of related data, and it consists of
columns and rows.
• Databases are useful for storing information categorically.
A company may have a database with the following
tables:
• Employees
• Products
• Customers
• Orders
• PHP combined with MySQL are cross-platform (you can
develop in Windows and serve on a Unix platform)
• A query is a question or a request.
• We can query a database for specific information and
have a record set returned.
• Look at the following query (using standard SQL):
SELECT LastName FROM Employees
• The query above selects all the data in the "LastName"
column from the "Employees" table.
 PHP 5 and later can work with a MySQL database using:
• MySQLi extension (the "i" stands for improved)
• PDO (PHP Data Objects)
 Earlier versions of PHP used the MySQL extension.
However, this extension was deprecated in 2012.
• The CREATE DATABASE statement is used to create a
database in MySQL.
• The following examples create a database named
"myDB":
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);
}
// Create database
$sql = "CREATE DATABASE myDB";
if ($conn->query($sql) === TRUE) {
echo "Database created successfully";
} else {
echo "Error creating database: " . $conn->error;
}
$conn->close();
?>

Web programming

  • 1.
  • 2.
     PHP ==‘HYPERTEXT PREPROCESSOR’  open-source, server-side scripting language  Used to generate dynamic web-pages  PHP scripts reside between reserved PHP tags • This allows the programmer to embed PHP scripts within HTML pages
  • 3.
     Interpreted language,scripts are parsed at run-time rather than compiled beforehand  Executed on the server-side  Source-code not visible by client • ‘view source’ in browsers does not display the PHP code  Various built-in functions allow for fast development  Compatible with many popular databases
  • 4.
     PHP isa general-purpose server-side scripting language originally designed for web development to produce dynamic web pages .  PHP can interact with My SQL databases.
  • 5.
     Structurally similarto C/C++  Support procedural and object-oriented paradigm (to some degree)  All PHP statements end with a semi-colon  Each PHP script must be enclosed in the reserved PHP tag <?php …… ?>
  • 6.
     Standard C,C++, and shell comment symbols. //C++ and java-style comment # shell-style comments /* C-style comments These can span multiple lines*/
  • 7.
     PHP variablesmust begin with a “$” sign.  Case-sensitive  Global and locally-scoped variables. • global variables can be used anywhere • local variables restricted to a function or class  Certain variable names reserved by PHP • form variables ($_POST, $_GET) • server variables($_ SERVER)  Etc.
  • 8.
    • MySQL isa 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
  • 9.
    • The datain a MySQL database are stored in tables. A table is a collection of related data, and it consists of columns and rows. • Databases are useful for storing information categorically. A company may have a database with the following tables: • Employees • Products • Customers • Orders
  • 10.
    • PHP combinedwith MySQL are cross-platform (you can develop in Windows and serve on a Unix platform)
  • 11.
    • A queryis a question or a request. • We can query a database for specific information and have a record set returned. • Look at the following query (using standard SQL): SELECT LastName FROM Employees • The query above selects all the data in the "LastName" column from the "Employees" table.
  • 12.
     PHP 5and later can work with a MySQL database using: • MySQLi extension (the "i" stands for improved) • PDO (PHP Data Objects)  Earlier versions of PHP used the MySQL extension. However, this extension was deprecated in 2012.
  • 13.
    • The CREATEDATABASE statement is used to create a database in MySQL. • The following examples create a database named "myDB":
  • 14.
    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); } // Create database $sql = "CREATE DATABASE myDB"; if ($conn->query($sql) === TRUE) { echo "Database created successfully"; } else { echo "Error creating database: " . $conn->error; } $conn->close(); ?>