Professional Documents
Culture Documents
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)
6/9/2019 JavaScript 2
What does PHP code looks like
Structurally similar to C/C++
<?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 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”;
• ?>
die
• <?php
• Die “welcome”
• Die “php”
• ?>
Output:welcome
6/9/2019 JavaScript 6
Basics of PHP
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
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