PHP

First intall xampp and vs code for php envirnoment

Installing xampp and php is most easy configuration


After installing xampp you can start 
Aapche and mysql service

you get xampp folder inside your c drive after you installation

inside xampp folder open htdocs folder

every floder inside htdocs represents one web project its that simple


PHP is very interesting because we actually write the php code between the html code

<?php     code goes here ?>

so like html php has opening and closing as in above in

echo is first thing you need to learn while hearing php

echo means to show or print

so it display the value

after echo we must include number or string 

for string double quotation is required

We can also print variable

you all know what variable is?

Yes Definitely variable is the value in the memory which keeps on changing

variable is define in php by using $ sign in front 

numeric variable

$variable++ post increment

++$variable  pre increment 

similarly

$variable-- post decrement

--$variable  pre decrement




Logical operator

Logical operator in PHP are 

and(&&)

or(||)

xor = if any one true or other is false than its xor of  2 number is true

not(!)


var_dump( ) is a function which is used to display data type

This function displays structured information about one or more expressions that includes its type and value.


Data types in php

  1. String
  • Integer
  1. Float
  2. Boolean
  3. Array
  4. object
Aarau is the collection of many things
array can hold more than one value at a time it can be created using array function


$language= array("python","c++","php","nodejs")
print $language[1]==> c++
string are the words or characters

there are many methods of array like
  • count()==> shows no of data in array



Constant are the value which cannot be changed


constant are usually define at that the top of program

for example

<?php

define('PI',3.14);

?>



Comparison operator

It returns Boolean value i.e. either true or false like boolean


so with the result of comparison and relational operator we can so different conditional statements

like

if .... else  statement

if (condition)

{

echo "something"

}

else

{

echo "other thing"

}



if ... else if ..... else



loops in php


1) while (condition){}

2) do {


} while(condition)


3) for ($a=initial;$a< ; counter($a++,$a--))

{

}


4) for each loop


foreach(arrayname as $value){

    echo "<br> the value for for each loop is <br>"

    echo $value

}



function:

function is the set of code that do certain task


We can define our own function which is called user define function

And there are also many build in function in php

strlen( )= gives the length of string

str_word_count( ) = count the number of words

strrev( ) = This reverse the string

strpos($str,"name')

str_replace("string need to be replace", "desire string", $str)



 





connecting database

after install xampp just turn on apache and mysql server

then goto http://localhost/phpmyadmin/

create a new data base 

then to configure data base

make a project/folder inside htdocs folder inside xampp

inside project folder make config.php file and

write the following code

<?php
$con=mysqli_connect("localhost","root","");

if(!$con)
{
    die("error in database connection");
}
$db=mysqli_select_db($con,"dbname");

if(!$db)
{
    die("error in database selection");
}
?>


What is PHP session?

 PHP session is used to manage information across different pages

as we enter detail in website we get good user experience from that detail in our php application

we start session with the help of session_start() function which is the build in function of php

we start session when we verify the login information

if the user name and password is match we actually start session

but if the user name and password is not match we don't start session instead we send user the enter right credentials

After session start we can actuuly verify session variable

$_SESSION['keys']='values'

Comments