What is php



Php kya hai

Php is a server side scripting language and a powerful tool which is very good for website development. PHP is also used for content management system, this language is easily embedded in html. Popular websites like Facebook are also built on PHP.  It requires a local server to work like Xampp, wamp, lamp etc.


 How to use php


 To use php, first we have to write the php script in notepad, to start the php script we start by typing <?php  and to close ?> to close the script, and then by applying .php extension to it  After that go to the WWW folder and if it is XAMPP then paste it in htdocs, otherwise go to WWW in wamp and paste it inside the project, then go to your browser and run it on local host  Open that file by opening then the PHP script will open


 Types of data in PHP


 There are many types of data types in php.


 1-integer


 There are integer numbers inside it, which is a whole number with no decimal point inside it, one has to use comma to use it like 1,2,3 or 123

Example


 $var = 67;


 echo $var;


 2- String


 It is a sequence of characters, it contains letters and special characters, to use it, single quote '' or "" quote has to be used.


 Example


 $var = "this is string";


 echo $var;


 3- Floating Point Numbers-


 Floating point numbers are also known as real numbers such as 4.56


 Example


 $var = 67.5;


 echo $var;


 4- booleans -


 Contains data such as True or False or 0 or 1


 Example


 $var = true;


 echo $var;


 5- arrays -


 It is a group of any data, inside it more than one data is stored in a variable like array of colour, array of city


 Example


 $color = array("green" , "white" , "blue" , ​​"yellow");


 echo $color;


 6- null -


 This type of data shows that there is no data store in this variable i.e. empty


 Example


 $var = "null";


 echo $var;


 What is php operators


 In scripting language, operators are those symbols with the help of which two variables are processed or relationship is established, let us know how many types of PHP are there.


 1- arithmetic operator


 - Those operators with the help of which two variables are added or subtracted are called arithmetic operators.


 Example


 $var1 = 50;


 $var2 = 20;


 echo $var1+$var2;


 echo "<br>"


 echo $var1-$var2;


 echo "<br>"


 echo $var1*$var2;


 echo "<br>"


 echo $var1/$var2;


 echo "<br>"


 2- assignment operator


 An operator which is used to assign something to a variable is called an assignment operator.


 Example


 $var1 = 50;


 $var1+=1;


 echo "<br>"


 $var1-=1;


 echo "<br>"


 $var1*=2;


 echo "<br>"


 $var1/=2;


 Compression operator


 With the help of this type of operator, two variables are compared.


 Example


 $var1 = 50;


 $var2 = 20;


 echo $var1>$var2;


 echo "<br>"


 echo $var1<$var2;


 echo "<br>"


 echo $var1==$var2;


 echo "<br>"


 echo $var1=$var2;


 Logical operator


 This type of operator is useful for results like true or false.


 If and else statement


 This type of statement is used to apply condition, if it happens then it will happen otherwise it will be like statement

Example

$age = 50;

If ($age>18){

echo "you can go to the party";

}

else ($age<18){

echo "you can not go to the party";

}

While function


 Using a while loop, it will repeat the output of the code and it will continue to repeat until the condition applied is false, as soon as it becomes false it will stop repeating. Example of this is given below


 $a=0


 While ($a<=10){


 echo "the value of a is";


 echo $a;


 $a++;


 ,


 use array with while


 while($a<count($langauges)){


 Echo "<br>the value of a is";


 echo $language [$a];


 $a++;


 ,


 Use of do while


 do{


 Echo "<br>the value of a is";


 echo $a;


 $a++


 }while ($a<10);


 Use of loop


 $a=200;


 for ($a=0; $a<10; $a++){


 echo "<br> the value of a from the for";


 echo $a;


 ,



 Mathematics example of php


 These are the codes of mathematics inside php, with the help of which the output of any input can be easily seen.


 echo "sqrt(9);


 echo "bindec(101);


 echo "decbin(9);


 echo "binhex(101);


 echo "hexbin(CF);


 MySQL server in PHP


 very easy way to connect to mysql database server in php


 $connect=mysqli_connect("local host", "root", "");


 In this, mysqli_connect is used to connect to the database, the same local host means on which database server is running, if there is a ip then it will be the ip, root is its user id from which to open the database server and the password is null.  If you want to connect to a database named test in the database server, then for that


 $connect=mysqli_connect("local host", "root", "", "test");


 Create table in database


 Inside php, the same command of sql is used to store any data in the table, the only difference is that we store the data by creating a variable in it.



 $table="create table mohit(id int(3), first_name varchar(20), last_name varchar(20), dob date)";


 If mysqli_query($connect, $table){


 Echo "table created successfully";


 } else{


 echo "table not created"


 ,



 Insert data into  table in database


 $connect=mysqli_connect("local host", "root", "", "test");


 $insert= "insert into mohit values ​​('1', 'mohi', 'shukla', '08-09-1980), ('2', 'ramesh', 'singh', '04-03-1970')  ";


 If mysqli_query($connect, $insert){


 echo "data insert  successfully";


 } else{


 echo "data not inserted successfully"


 ,


 In this way you can store your data by creating a table inside the database.


 Through this post, an attempt has been made to explain the basic of PHP to you, hope you have understood.


Basic of PHP language सीखना चाहते हैं तो वह भी सिख सकते हैं

 r language basic program 

 r language examples 

r language for data science

R language tutorial

आसा करता हु की आपको PHP आसानी से समझ मे आ गया होगा आपको उसके बेसिक्स पता चल चुके होंग

Types of deta in PHP

PHP full course in hindi

mysql commands |mysql queries |mysql advantages |mysql basic commands |mysql basic |mysql basic queries |mysql database tutorial  |mysql language