0% found this document useful (0 votes)
78 views

PHP WITH MYSQL NOTES

PHP, which stands for Hypertext Preprocessor, is an open-source server-side scripting language used for web development that allows for dynamic page content and database integration. It is easy to learn and can be embedded within HTML, making it versatile for creating web applications. PHP variables have specific naming rules and scopes, including local, global, and static, which dictate their accessibility within scripts.

Uploaded by

tmodi9680
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
78 views

PHP WITH MYSQL NOTES

PHP, which stands for Hypertext Preprocessor, is an open-source server-side scripting language used for web development that allows for dynamic page content and database integration. It is easy to learn and can be embedded within HTML, making it versatile for creating web applications. PHP variables have specific naming rules and scopes, including local, global, and static, which dictate their accessibility within scripts.

Uploaded by

tmodi9680
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
You are on page 1/ 6

PHP WITH MYSQL NOTES

PHP Introduction

 The term PHP is an acronym for – Hypertext Preprocessor. PHP is a server-side


scripting language designed specifically for web development. It is an open-source
which means it is free to download and use. It is very simple to learn and use. PHP
scripts are executed on the server

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

Basic PHP Syntax


A PHP script can be placed anywhere in the document.

A PHP script starts with <?php and ends with ?>:

<?php

// PHP code goes here

?>

Example 1.

A simple .php file with both HTML code and PHP code:

<!DOCTYPE html>

<html>

<body>

<h1>My first PHP page</h1>

<?php

echo "Hello World!"; ?>


</body>

</html>

PHP Installation

 Find a web host with PHP and MySQL support

 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

 Cross-platform: PHP runs on many operating systems

 Database integration: PHP supports many databases, including MySQL and


PostgreSQL

 Server-side scripting: PHP scripts are executed on the server, which then generates
HTML for the browser

 Easy to use: PHP is easy to learn and execute

 Great compatibility with HTML: You can easily embed PHP code in HTML

BENEFITS OF USING PHP AND MY SQL

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

Variables are "containers" for storing information.

A variable can have a short name (like $x and $y) or a more descriptive name
($age, $carname, $total_volume).

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, 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>

PHP Variables Scope

PHP has three different variable scopes:

 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

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>";

?>

</body>

</html>
2. Global Scope

A variable declared outside a function has a GLOBAL SCOPE and can only be accessed
outside a function:

Ex. <!DOCTYPE html>

<html>

<body>

<?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>";

?>

</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>

You might also like