PHP Presentation
PHP Presentation
Echo is marginally faster than Print. Print is marginally slower than Echo.
<?php <?php
$name=“Karan”; $name=“Karan”;
echo “He is $name”; print “He is $name”;
echo ‘He is $name’; print ‘He is $name’;
?> ?>
Explode() vs Implode()
<?php
$arr = array('Hello','World!','Beautiful','Day’);
echo implode(" ",$arr);
?>
<?php
$str = "Hello world. It's a beautiful day.";
print_r (explode(" ",$str,3));
?>
Array ( [0] => Hello [1] => world. [2] => It's a beautiful day. )
foreach loop
foreach ($array as $value)
{
code to be executed;
}
Include/require
The include (or require) statement takes all the text/code/markup that exists in the specified file and copies
it into the file that uses the include statement.
Also known as HTTP Cookie, Web Cookie or Browser Cookie
Cookies are small, randomly encoded text files that identifies a user.
setcookie(name, value, expire);
setcookie(“User”, “Karan”, time() + (seconds));
To access Cookie use Global Variable $_COOKIE [“Cookie_Name”];
setcookie(name, value, time()-3600 );
Note: Cookies are stored on Client’s System.
Sessions is a way to make data accessible across various pages of a website.
To start a session : session_start();
Session variables are set with the PHP global variable:
$_SESSION[“Session_name”].
print_r($_SESSION);
session_unset() Removes all Session Variables
session_destroy() Destroy the Session
Make sure the form uses the method=“POST”
Enctype=“multipart/form-data”
<input type=“file” name=“abc” id=“xyz”>
file_uploads = On in php.ini
$_FILES [‘filenameattr’][‘temp_name’]
$_FILES [‘filenameattr’][‘name’]
$_FILES [‘filenameattr’][‘size’]
$_FILES [‘filenameattr’][‘type’]
$_FILES [‘filenameattr’][‘error’]
$myfile = fopen(“File", “Mode") or die("Unable to open file!");
fread($myFile,filesize(“File"));
fclose($myfile);
fgets($myfile); - Reads a single line
feof($myfile); - Checks the end of file
fgetc($myfile);
fwrite($myfile,$text);
Two directives to be supplied :-
• SMTP – server address
• Sendmail_from – own email
Mail(“Email”,”Subject”,”$msg”, “headers”);
CMS stands for Content Management System.
Collaborative creation of document and other contents.
Allows end user to submit an article entered as plain text.
Control Panel
American company operating a worldwide online payments system that supports
online money transfers and serves as an electronic alternative to traditional paper
methods like cheques and money orders. The company operates as a payment
processor for online vendors, auction sites, and other commercial users, for which
it charges a small fee in exchange for benefits such as one-click transactions and
password memory.
IPN stands for Instant Payment Notification
Localhost/ci/
Localhost/ci/index.php/site/hello
Localhost/ci/
Model
Controller Model
<?php <?php
class Site extends CI_Controller class Math extends CI_Model
{ {
public function index() public function addStuffs()
{ {
echo "This is my first page"; return (1+2);
$this->add(); }
} }
public function add()
{
$this->load->model(“math”);
echo $this->math->addStuff();
}
}
Localhost/Ci/
View
Controller View/view_home.php
<?php <!DOCTYPE html>
class Site extends CI_Controller <html>
{ <head>
public function index() <title>
{ <?php echo $title; ?>
echo "This is my first page"; </title>
$this->home(); </head>
} <body>
public function home() <h1>Welcome To My First View</h1>
{ </body>
$data[“title”]=“Welcome”; </html>
$this->load->view(“view_home”,$data);
}
}
It is a frame work.
In computer systems, a framework is often a layered structure indicating what
kind of programs can or should be built and how they would interrelate.
Code Igniter is a powerful PHP framework with very small footprints.
It was created by EllisLab
Open source
Some important features of Code Igniter are :-
MVC based
Extremely Light Weight
Several Database support
Query Builder Database Support
Form & Data Validation
Session Management
File Uploading Classes
Pagination
Search engine friendly URLs
Flexible URIs Routing
Large Library of “Helper” function
$this->load->database('group_name');
Where group_name is the name of the connection group from your config file.
$config['hostname'] = "localhost";
$config['username'] = "myusername";
$config['password'] = "mypassword";
$config['database'] = "mydatabase";
$this->load->database($config);
URI : Uniform Resource Identifier is a string designed for unambiguous identification of
a resource
application/config/routes.php
www.example.com/blog/user/34
$route['blog/Joe'] = 'blogs/users/34';
www.example.com/blog/Joe
• MVC PHP framework
• Created by Taylor Otwell
• Laravel provides 20 built in library and modules
• It has various features to test modules
• Flexible Routing
• Configuration management
• Email Class
• Authentication
Laravel over CodeIgniter
• Inbuilt user authentication
• Inbuilt CLI support
• Log Management
• Template Engine
• ORM – Object Relational mapping
• MySQL is a database system used on the web
• MySQL is a database system that runs on a server
• MySQL is ideal for both small and large applications
• MySQL is very fast, reliable, and easy to use
• MySQL uses standard SQL
• MySQL compiles on a number of platforms
• MySQL is free to download and use
• MySQL is named after co-founder Monty Widenius's daughter: My
phpMyAdmin is a free software tool written in PHP, intended to handle the
administration of MySQL over the Web.
3 ways to connect to and disconnect from Database :-
• MySQLi (object-oriented) $conn->close();
• MySQLi (procedural) mysqli_close($conn);
• PDO $conn = null;
if ($result->num_rows > 0)
{
while($row = $result->fetch_assoc())
{
action on $row[“User”]…
}
}