Important and Useful code in PHP

Connect to Mysql using PHP

<?php 
$con = mysqli_connect("localhost","username","password");
if (!$con)
  {
  die('Could not connect: ' . mysqli_error());
  }

mysqli_select_db($con,"your_database_name");
?>

To display current date and time

<?php 
$current_date_time = date('Y-m-d H:i:s'); //in mysql storing format
?>

Convert date format from ‘d-m-Y’ to ‘Y-m-d’

<?php 
$dob = $_POST['dob']; //value get from the form
$covert_dob = date("Y-m-d",strtotime($dob));
?>

show a number to 2 decimal places

<?php 
$foo = "54.104";
echo number_format((float)$foo, 2, '.', ''); //output 54.10
$ful = "54";
echo number_format((float)$ful, 2, '.', ''); //output 54.00
?>