MsSQL - PHP Connection codes

<?php
// codes required for mssql connection
$serverName = "DESKTOP-KC5F9RS"; // mssql server name will come here.
$connectionInfo = array( "Database"=>"Database_Name"); // db name will come here.
$conn = sqlsrv_connect($serverName, $connectionInfo);
if ($conn) {
echo "Connection Successfull <hr>";
}
else
{
echo "Connection Failed! <hr>";
die(print_r(sqlsrv_errors(), true));
}
?>

Even Odd Program in PHP

Even numbers are those which are divisible by 2. Numbers like 2,4,6,8,10, etc are even.

<?php
$number=87;
if($number%2==0)
{ echo "$number is Even Number";
}
else
 {
echo "$number is Odd Number";
}
?>



Switch Statement in PHP

The switch statement is similar to a series of if statements on the same expression.

The following two examples are two different ways to write the same thing, one using a series of if and else-if statements, and the other using the switch

<?php
$i=2;

if ($i == 0)
{
 echo "$i equals 0 ";
 }
 else if ($i == 1)
 {
echo "$i equals 1 ";
 }
else if ($i == 2) 
echo "$i equals 2 ";
}
//using switch
switch ($i)
{
case 0:
echo "$i equals 0 ";
break;
case 1:
echo "$i equals 1 ";
break;
case 2:
echo "$i equals 2 ";
 break;
}

?>



PHP TUTORIALS