Thursday, 10 September 2015

Object-Oriented -Programming in PHP for insert ,update ,delete ,display code guidance

06:32

COMPARISON    CODE     PRACITCE    for  BASIC   PHP  AND ADVANCE  PHP  CODEING :

first create table Example:
SQL>create table example
(id int,
name  varchar(200));

SIMPLE CONNECTIVITY CODE :
(1)write  code for simple_connect.php file:
<?php
$con=mysql_connect("localhost","root","");
mysql_select_db("mandar",$con);
if(!$con)
{
echo      “not connected ”;
}
?>



ADVANCE CONNECTIVITY CODE:

(1)write code for  advance_connect.php file:

<?php
class db
{
                var $host="localhost";
                var $user="root";
                var $password="";
                var $database="mandar";
                var   $con;

function __construct()

{
                $this->con=mysql_connect($this->host,$this->user,$this->password);
               
                if(!$this->con)
                {
                echo "not connected";
               
                }
               
                mysql_select_db($this->database,$this->con) or die(mysql_error());

}
               
}
$obj=new db();   // CONSTRUCTOR AUTOMATICLY CALLED WHEN OBJECT IS CREATED

?>



SIMPLE    INSERT    EXAMPLE:

(1)write code for simple_inset.html  file:

<form action="simple_insert.php" method="post">
Id <input type="text" name="id">
Name <input type="text" name="name">
<input type="submit" name="submit" value="insert">

(2)write code for  simple_insert.php file:

<?php
include("simple_connect.php");

$id=$_POST['id'];
$name=$_POST['name'];
$sql="insert into example(id,name)values('$id','$name')";

$result=mysql_query($sql);

if($result)
{
echo "Inserted";
}
else
{
echo "Not Inserted";
}

?>

ADVANCE INSERT EXAMPLE:

(1)write code for advance_insert.html:

<form action="advance_insert.php" method="post">
Id <input type="text" name="id">
Name <input type="text" name="name">
<input type="submit" name="submit" value="insert">


(2) write  code for   advance_insert.php  file :
<?php
include("advance_connect.php");

class  myinsert

{

function  insert()
{
$id=$_POST['id'];
$name=$_POST['name'];

$sql="insert into example(id,name)values('$id','$name')";

$result=mysql_query($sql);
if($result)
{
echo "record inserted";               
               
}
else
{
               
echo "record not inserted";       
}

}

}

$myobj=new myinsert();
$myobj->insert();

?>



SIMPLE     UPDATE EXAMPLE:

(1)write code for  simple _udate.html file:

<form action="simple_update.php" method="post">
Id <input type="text" name="id">
Name <input type="text" name="name">
<input type="submit" name="submit" value="update">

(2)write code for simple_update.php file:

<?php
$id=$_POST['id'];
$name=$_POST['name'];

include("simple_connect.php");

$sql="update example set id='$id' where name='$name'";

$result=mysql_query($sql);
if($result)
{
echo "Reccord Update Successfully";
}
else
{
echo "Not Update";
}

?>

NOW WRITE CODE FOR   ADVANCE     UPDATE EXAMPLE:

(1)write code for advance_update.html file:

<form action="advance_update.php" method="post">
Id <input type="text" name="id">
Name <input type="text" name="name">
<input type="submit" name="submit" value="update">

(2)write   code   for advance_update.php file:

<?php
include(advance_connect.php);

class updateclass
{
function update()

{
$id=$_POST['id'];
$name=$_POST['name'];

$sql="update example set id='$id' where name='$name'";

}
}

$obj=new updateclass();
$obj->update();

?>



SIMPLE   DELETE  EXAMPLE:

(1)write code for simple_delete.html file:

<form action="simple_delete.php" method="post">
Id <input type="text" name="id">
<input type="submit" name="submit" value="submit">



(2)write   code   for   simple_delete.php      file:
<?php

$id=$_POST['id'];

include("simple_connect.php");

$sql="delete from example where id='$id'";

$result=mysql_query($sql) or die(mysql_error());

if($result)
{
echo "deleted";
}
else
{
echo "not deleted";
}

?>

ADVANCE  DELETE  EXAMPLE :

(1)write code for  advance _delete.html  file:

<form action="advance_delete.php" method="post">
Id <input type="text" name="id">
<input type="submit" name="submit" value="submit">

(2) write   code   for  advance_delete.php     file :

<?php

include('advance_connect.php');

class  deleteclass
{
function delete()
{
$id=$_POST['id'];

$sql="delete from example where id='$id'";



$result=mysql_query($sql);
if ($result)
{
echo "deleted";
}
else
{
echo "not deleted";
}
}
}

$obj=new  deleteclass();
$obj->delete();
?>

NOW  SIMPLE  DISPLAY EXAMPLE :

(1)write code  simple_display.php  file :

<?php
$con=mysql_connect("localhost","root","");
mysql_select_db("mandar",$con);

$sql="select *from example";

$result=mysql_query($sql);
while($row=mysql_fetch_array($result))
{
echo $row['id']." ";
echo $row['name']." ";
echo '<br>';
}

?>

ADVANCE   DISPLAY   EXAMPLE  :

(2)write    code for  advance _display.php file :

<?php
include('advance_connect.php');

class displayclass
{
function display()
{
$sql="select *from example";

$result=mysql_query($sql) or die(mysql_error());

while($row=mysql_fetch_array($result))
{
echo $row['id']." ";
echo $row['name']." ";
echo '<br>';
}
}
}
$obj=new displayclass();
$obj->display();

?>


SIMPLE  SEARCH EXAMPLE :

(1)write code for simple_search.html file:

<form action="simple_search.php" method="post">
Name <input type="text" name="name">
<input type="submit" name="submit" value="search">

(2)write   code for simple_search.php file:

<?php
$name=$_POST['name'];
$con=mysql_connect("localhost","root","");
mysql_select_db("mandar",$con);

$sql="select *from example where name='$name'";

$result=mysql_query($sql)or die(mysql_error());
$num=mysql_num_rows($result);
if($num>0)
{
while($row=mysql_fetch_array($result))
{
echo $row['id']." ";
echo $row['name']." ";
echo '<br>';
}
}
else
{
echo "no record match";

}


?>

NOW   FOR   ADVANCE SEARCH EXAMPLE:

(1)write code for advance_search.html file:

<form action="advance_search.php" method="post">
Name <input type="text" name="name">
<input type="submit" name="submit" value="search">

(2)now  write code for advance_search.php file:

<?php
include('advance_connect.php');
class searchclass
{
function search()
{
$name=$_POST['name'];
$sql="select *from example where name='$name'";

$result=mysql_query($sql) or die(mysql_error());

while($row=mysql_fetch_array($result))
{
echo $row['id']." ";
echo $row['name']." ";
echo '<br>';
}

}
}

$myobj=new searchclass();

$myobj->search();
?>


Written by

We are Creative Blogger Theme Wavers which provides user friendly, effective and easy to use themes. Each support has free and providing HD support screen casting.

1 comments:

  1. Hey Nice Blog!! Thanks For Sharing!!!Wonderful blog & good post.Its really helpful for me, waiting for a more new post. Keep Blogging!
    best java training in coimbatore
    php training in coimbatore
    best php training institutes in coimbatore

    ReplyDelete

PHP Training Mumbai, PHP MySQL Training Mumbai, PHP Course Mumbai, PHP Institute Mumbai

 

© 2013 PHP TRAINING IN MUMBAI BY OM SIR . All rights resevered. Designed by OM SIR

Back To Top