PHP WITH MYSQL NOTES
PHP WITH MYSQL NOTES
PHP Introduction
PHP can create, open, read, write, delete, and close files on the server
<?php
?>
Example 1.
A simple .php file with both HTML code and PHP code:
<!DOCTYPE html>
<html>
<body>
<?php
</html>
PHP Installation
Install a web server on your own PC, and then install PHP and MySQL
FEATURES OF PHP
PHP is a server-side scripting language that is used to develop web applications. It has many
features, including:
Open source: Anyone can use PHP and its components for free
Server-side scripting: PHP scripts are executed on the server, which then generates
HTML for the browser
Great compatibility with HTML: You can easily embed PHP code in HTML
PHP and MySQL are open-source server-side programming languages used to create
dynamic websites. They provide flexibility, as they can be used and manipulated on any
operating system. PHP and MySQL work together to provide fast web page response times
even with slow internet and data speed.
COMMENTS IN PHP
PHP Variables
A variable can have a short name (like $x and $y) or a more descriptive name
($age, $carname, $total_volume).
A variable starts with the $ sign, followed by the name of the variable
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.
<!DOCTYPE html>
<html>
<body>
<?php
$txt = "W3Schools.com";
echo "I love $txt!";
?>
</body>
</html>
local
global
static
1.Local scope:
A variable declared within a function has a LOCAL SCOPE and can only be accessed
within that function:
<!DOCTYPE html>
<html>
<body>
<?php
function myTest() {
$x = 5; // local scope
myTest();
?>
</body>
</html>
2. Global Scope
A variable declared outside a function has a GLOBAL SCOPE and can only be accessed
outside a function:
<html>
<body>
<?php
$x = 5; // global scope
function myTest() {
myTest();
?>
</body>
</html>
3.Static scope
<!DOCTYPE html>
<html>
<body>
<?php
function myTest() {
static $x = 0;
echo $x;
$x++;
myTest();
echo "<br>";
myTest();
echo "<br>";
myTest();
?>
</body>
</html>