Lab1
PHP(Hypertext Preprocessor) is widely used server sripting language by Rasmus Lerdorf in the year
1994.
features
• powerful tool for making dynamic and interactive web pages
• can integrate with almost all popular databases like MySQL, Oracle, Sybase, Informix,
Microsoft SQL Server etc.
• C like Syntax and easy to learn.
• Object oriented scripting language.
• easily embeddable into HTML
Prime number
A number which is only divisible by 1 and itself is called prime number. Numbers 2, 3, 5, 7, 11, 13, 17,
etc. are prime numbers.
Lab2
You can send data from one PHP page to another PHP page by using the $_GET or $_POST method.
The $_GET method appends the data to the URL, making it visible in the address bar.
The $_POST method is a more secure way of sending data, as the data is not visible in the URL and is
transmitted in the body of the HTTP request.
For example, to send data from page1 to page2 using the $_POST method, you can write the
following code in page1:
<form action="page1.php" method="post">
<input type="text" name="name">
<input type="submit" value="submit">
</form>
And in page2, you can retrieve the data like this:
<?php
$student = $_POST['name'];
echo "Data received: " . $student;
?>
Lab3
The isset() function checks whether a variable is set, which means that it has to be declared
and is not NULL.
This function returns true if the variable exists and is not NULL, otherwise it returns false.
The arithmetic operators are used to perform simple mathematical operations like addition,
subtraction, multiplication, etc. Below is the list of arithmetic operators along with their
syntax and operations in PHP.
Operator Name Syntax Operation
+ Addition $x + $y Sum the operands
– Subtraction $x – $y Differences the operands
* Multiplication $x * $y Product of the operands
/ Division $x / $y The quotient of the operands
% Modulus $x % $y The remainder of the operands
Lab4
PHP String Function
strtoupper() and strtolower() Function
It returns the string after changing the cases of its letters.
• strtoupper(): It returns the string after converting all the letters to uppercase.
• strtolower(): It returns the string after converting all the letters to lowercase.
Syntax
strtoupper(string)
strtolower(string)
strlen() Function
It returns the length of the string i.e. the count of all the characters in the string including whitespace
characters.
Syntax
strlen(string or variable name);
strrev() Function
It returns the reversed string of the given string.
Syntax
strrev(string or variable name);
str_word_count() Function
It is used to return information about words used in a string like the total number of words in the
string, positions of the words in the string, etc.
Syntax
str_word_count ( $string , $returnVal, $chars );
ucwords() Function
It is used to convert the first character of every word in a string to upper-case.
Syntax
string ucwords ( $string, $separator )
str_replace() Function
It is used to replace all the occurrences of the search string or array of search strings by replacement
string or array of replacement strings in the given string or array respectively.
Syntax
str_replace ( $searchVal, $replaceVal, $subjectVal, $count );
lab5
Array Functions
count() function
PHP count() function counts all elements in an array.
Syntax:
count($array)
array_reverse() function
PHP array_reverse() function returns an array containing elements in reversed order.
Syntax:
array_reverse($array)
array_search() function
PHP array_search() function searches the specified value in an array. It returns key if search is
successful.
Syntax
array_search($value, $array)
array_intersect() function
PHP array_intersect() function returns the intersection of two array. In other words, it returns the
matching elements of two array.
Syntax
array_intersect ( $array1 , $array2)
array_merge() function
The array_merge() function merges one or more arrays into one array.
Syntax
array_merge(array1, array2)
lab6
The date_default_timezone_set() function is used to set the default timezone used by all the
functions in a script.
Syntax
date_default_timezone_set(timezone)
timezone (Mandatory)
This is the string representing the time zone you need to set as default.
The date() function accepts a format string as a parameter, formats the local date/time in the
specified format and returns the result.
Syntax
date(format)
format Required. Specifies the format of the outputted date string.The following characters can be used:
h - 12-hour format of an hour (01 to 12)
H - 24-hour format of an hour (00 to 23)
i - Minutes with leading zeros (00 to 59)
s - Seconds, with leading zeros (00 to 59)
a - Lowercase am or pm
A - Uppercase AM or PM
Lab7
GCD (Greatest Common Divisor)
GCD stands for Greatest Common Divisor. GCD of two numbers is the largest positive integer that
completely divides both the given numbers.
Example: GCD(10,15) = 15, GCD(12,15) = 3.
LCM (Least Common Multiple)
LCM stands for Least Common Multiple. It is a method to find the lowest common multiple between
the two numbers. LCM of two numbers is the lowest possible number that is divisible by both
numbers.
Examples: LCM(10,15) = 30, LCM(12,15) = 60.
Problem Solution
1. Take two numbers as input.
2. Find the greater of the two numbers.
3. Keep on dividing the greater number by the smaller number until remainder becomes 0.
4. When the remainder becomes 0 store the smaller number as the GCD of two numbers.
5. If the maximum is completely divisible by both the numbers, store the maximum number as LCM.
6. Else keep on increasing the maximum by one until it is completely divisible by both the numbers.
7. Finally store the new value of maximum as LCM.
Recursion Functions
A recursive function is such a function that calls itself until a certain condition is satisfied.
Lab8
Constructor
In PHP, a constructor allows you to initialize an object's properties upon the creation of the object.
The constructor function starts with two underscores (__) and if we create a __construct() function,
then PHP will automatically call this function when we create an object from a class.
function __construct()
// initialize the object and its properties by assigning
//values
Destructor
Destructor is a special member function which is exactly the reverse of the constructor method.
When it is called an instance of the class is deleted from the memory. The Destructor function starts
with two underscores (__) and if we create a __destruct() function, then PHP will automatically call
this function at the end of the script.
function __destruct()
// destroying the object or clean up resources here
}
Lab9
Step to create Database and Table in MySQL
Step1: click on Start button of MySQL.
Step2: click on admin button of MySQL for creating database and table.
Step3: Click on New for creating database
Step4: Give database name as stud and click on create button
Step5: After creation of database create table student with 3 columns
Step6: Create table structure (id, name email) make sure you select id as primary and click on save
button.
MySQL
MySQL is a very popular open-source relational database management system (RDBMS).
MySQLi
MySQLi is an extension to MySQL API available in PHP and is introduced from PHP 5.0 onwards. It is
also known as MySQL improved extension.
mysqli_connect()
The mysqli_connect() function in PHP is used to connect you to the database.
mysqli_connect_error()
The mysqli_connect_error() function returns the error description from the last connection error, if
any.
mysqli_query()
mysqli_query() function performs a query against a database.
mysqli_error()
The mysqli_error() function returns the description of the error occurred during the last MySQLi
function call.
mysqli_num_rows()
The mysqli_num_rows() function returns the number of rows in a result set.
mysqli_fetch_assoc()
The mysqli_fetch_assoc() function fetches a result row as an associative array.
mysqli_close()
The mysqli_close() function closes a previously opened database connection.
Lab10
Laravel
Laravel is a powerful MVC PHP framework, designed for developers who need a simple and elegant
toolkit to create full-featured web applications. Laravel was created by Taylor Otwell.
Composer
Composer is a tool which includes all the dependencies and libraries. It allows a user to create a
project with respect to the mentioned framework.
Artisan
Command line interface used in Laravel is called Artisan. It includes a set of commands which assists
in building a web application.