Location via proxy:   [ UP ]  
[Report a bug]   [Manage cookies]                
0% found this document useful (0 votes)
10 views

Chapter 4 Slide 2 Lecture-PHPMySQL

PHP is a server-side scripting language commonly used for web development. It allows developers to generate dynamic web pages through code execution on the server. Some key points about PHP include that it is open-source, uses a basic syntax similar to C/C++, and supports both procedural and object-oriented programming. PHP code is executed on the server-side and can interface with popular databases to retrieve and manipulate data.

Uploaded by

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

Chapter 4 Slide 2 Lecture-PHPMySQL

PHP is a server-side scripting language commonly used for web development. It allows developers to generate dynamic web pages through code execution on the server. Some key points about PHP include that it is open-source, uses a basic syntax similar to C/C++, and supports both procedural and object-oriented programming. PHP code is executed on the server-side and can interface with popular databases to retrieve and manipulate data.

Uploaded by

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

PHP Basics

University of Gondar
Faculty of Informatics
Computer Science Department

Internet Proramming

6/9/2019 JavaScript 1
PHP == ‘Hypertext Preprocessor’
What
Open-source, server-side scripting language
is
Used to generate dynamic web-pages
PHP
Executed on the server side (Web Server—Apache)

Various built-in functions allow for fast development

Compatible with many popular databases

6/9/2019 JavaScript 2
What does PHP code looks like
Structurally similar to C/C++

Supports procedural and object-oriented paradigm

All PHP statements end with a semi-colon

Each PHP script must be enclosed in the reserved PHP tag

<?php …?>

6/9/2019 JavaScript 3
Comment in PHP
// Single line comment
# single line comment
/* …… */ multi Line Comment
Variable in PHP
PHP variables must begin with a “$” sign
Case-sensitive ($Foo != $foo != $fOo)
Global and locally-scoped variables
Global variables can be used anywhere
Local variables restricted to a function or class

6/9/2019 JavaScript 4
Output Function of PHP
3 output function in php

Echo, print and die

All the same with slight programming difference

Echo and print are same except print accept only one parameter

Die is like echo except , die will stop the further execution

6/9/2019 JavaScript 5
Echo
• <?php
• Echo “welcome”;
• Echo “php”;
• ?>

Output: welcome php

die
• <?php
• Die “welcome”
• Die “php”
• ?>

Output:welcome

6/9/2019 JavaScript 6
Basics of PHP

Variable declaration use $, E. $name,$age

PHP is loosely typed language

PHP is a case sensitive Scripting Language

(.) is a concatenation operator


6/9/2019 JavaScript 7
Variable naming rule
Variable A variable name must start with letter or underscore

Naming Contain alpha-numeric char and underscore (a-z,A-Z,0-


9,’_’)
Variable name should not contain space

Variable name should not be a PHP keyword (echo, die)

Variable name should be descriptive

6/9/2019 JavaScript 8
Conditional and Loop Statement
Conditional
• If-Else
• Switch-Case
Loop
• For
• While
• Do-while
Operators
• +,*,-,/,%

6/9/2019 JavaScript 9
Insert One PHP file into Another

Insert the content of one PHP file into another

Can be done with include and require

The Two functions are identical except how they handle


errors
• Include() generate warning and continue the execution
• Require() generate fatal error and stop execution

6/9/2019 JavaScript 10
Predefined function PHP with MySQL
Mysqli_connect()->Is a function used to connect to the database server
<?php
$databaseHost = 'localhost';
$databaseName = 'test';
$databaseUsername = 'root';
$databasePassword = '';
$con = mysqli_connect($databaseHost, $databaseUsername, $databasePassword, $databaseName);
if (!$con)
{
Die(“connection error:”.mysqli_connect_error());
}
?>

6/9/2019 JavaScript 11
Predefined function PHP with MySQL
Mysqli_query()
• Function used to execute query
• $sql=“SELECT * FROM student”;
• $res=mysqli_query($con,$sql)
Mysqli_fetch_array
• Used to retrieve all recored from the query
• While($re=mysqli_fetch_array($res)){
• Echo $re[‘id’];
• Echo $re[‘name’];
•}

6/9/2019 JavaScript 12
Thank You

6/9/2019 JavaScript 13

You might also like