Thursday 7 March 2013

How To install PHP?



                         How  To Install  PHP
To start using PHP, you can:
  • Find a web host with PHP and MySQL support
  • Install a web server on your own PC, and then install PHP and MySQL.

However, if your server does not support PHP, you must:
  • install a web server
  • install PHP
  • install a database, such as MySQL.
                 How To create connection with database
Following code is used to create the connection with database:-
<? php
// Create connection
$con=mysqli_connect ("example.com","peter","abc123","my_db");

// Check connection
if (mysqli_connect_errno($con))
  {a
  echo "Failed to connect to MySQL: " . mysqli_connect_error ();
  }
?>

How to Close a connection
Following code is used to close a connection:-
<?php
$con=mysqli_connect("example.com","peter","abc123","my_db");

// Check connection
if (mysqli_connect_errno($con))
  {
  echo "Failed to connect to MySQL: " . mysqli_connect_error();
  }
mysql_close($con);
?>
How to create a Database
To create a Database following code is written:-
<?php
$con=mysqli_connect("example.com","peter","abc123");
// Check connection
if (mysqli_connect_errno())
  {
  echo "Failed to connect to MySQL: " . mysqli_connect_error();
  }

// Create database
$sql="CREATE DATABASE my_db";
if (mysqli_query($con,$sql))
  {
  echo "Database my_db created successfully";
  }
else
  {
  echo "Error creating database: " . mysqli_error();
  }
?>

No comments:

Post a Comment