PHP Using MySQL

MySQL

  • It is open source Relational Database Management System Implemented by Mysql AB corporation and adopted by Oracle Corporation.
  • PHP is providing php_mysql.dll library  for database.
  • Database server we are using to store input data server in web application
  • Database is a collection of database object like tables, users, views, etc.

php_myadmin

  • It is graphical user interface use to connect with mysql database.
  • It is an open source software available with xampp installation.
  • To open phpmyadmin URL address is http://localhost/phpmyadmin

Option Done By phpmyadmin

  • Insert.
  • Browse.
  • Structure.
  • SQL.
  • Search.
  •  Operation.
  • Export.
  • Import.
  • Drop.

PHP function to connect With database

mysql_connect:

  • Using this function we can create the connection between our application and SQL database server.
  • Argument  are servername, userid, password.

To connect with database

<?php
if($con-mysql_connec(“localhost”,”root”,””))
{
echo “Db connect”;
}
else
echo”mysql_error()”;
echo $con;
?>

mysql_error:-

  • To get the error message what is occured at time of SQL statement execution.

mysql_query:-

  • To Execute an Sql query mysql database.
mysql_query
<?php
$con=mysql_connect(“localhost”,”root”,””);
if(mysql_query(“create database new_db”,$con));
{
Echo “Db Created ”;
}else
Echo “mysql_error”;
?>

mysql_selete_db:-

  • To selete database from mysql server
  • Argument are database name and connection id (optional).
mysql_selete_db
<?php
mysql_connect(“localhost”,”root”,””);
mysql_selet_db(“new_db”);
if(mysqli_query(“create table abcd (int sno )”))
{
Echo “DB connected”;
}else
Echo “mysql_error()”;
?>

Following are some program for database connectivity

config.php
<?php
$con = mysql_connect(“localhost”,”root”,””) or die (mysql_error());
$db = mysql_select_db(“kushal_demo”) or die (mysql_error());
?>
Program For Registration Form With mysql connectivity

Registration From

<?php
include “config.php”;
extract($_POST);
if(isset($_POST[‘submit’]))
{
$fname=$_POST[‘fname’];
$lname=$_POST[‘lname’];
$gender=$_POST[‘gender’];
$dob =$_POST[‘dob’];
$email=$_POST[’email’];
$mobileno=$_POST[‘mobileno’];
$adress=$_POST[‘adress’];
$uname=$_POST[‘uname’];
$pass=$_POST[‘pass’];
$query1=”INSERT INTO `register` (`fname`, `lname`,`gender`, `dob`, `email`, `mobileno`, `adress`,`uname`,`pass`)
VALUES(‘”.$fname.”‘,'”.$lname.”‘,'”.$gender.”‘,'”.$dob.”‘,
‘”.$email.”‘,'”.$mobileno.”‘,'”.$adress.”‘,'”.$uname.”‘,'”.$pass.”‘)” or die (mysql_error());
$sql=mysql_query($query1);
}
?>

Program for Login using DB
User Name:
PassWord:

<?php
include ‘config.php';
if (!isset($_SESSION))
{
session_start();
}
if(isset($_POST[‘login’]))
{
$uname = $_POST[‘uname’];
$pass = $_POST[‘pass’];
$sql = “SELECT * FROM register WHERE uname= ‘$uname’
AND pass= ‘$pass'”;
$result = mysql_query($sql) ordie(mysql_error());
if ($result)
{
$count = mysql_num_rows($result);
if ($count == 1)
{
$_SESSION[“uname”] = $_POST[‘uname’];
header(“location:stdpro.php”);
} else
{
echo “Wrong Username or Password”;
}
}
}
?>

Leave a Reply

Your email address will not be published. Required fields are marked *