Monday, 21 November 2016

Using an Access Database with PHP

02:54

(1)First download    extension=php_pdo_odbc.dll     
(2)then copy it and paste inside your xampp path: "C:\xampp\php"
(3)now open your php.ini  file   open it from  path: "C:\xampp\php" and

remove   ;   from  extension=php_pdo_odbc.dll  

(4)after removing  ; you will get
(5) now create a  folder   "ms "  inside your   C:\xampp\htdocs\  and keep your   msaccess file products.mdb    database file  and create a table  product with two columns (pid ,pname )
now your path for database file  will be   "C:\xampp\htdocs\ms\products.mdb"

(6)now write code for   select .php file :

<?php
$dbName = $_SERVER["DOCUMENT_ROOT"] . "/ms/products.mdb";

echo  $_SERVER["DOCUMENT_ROOT"];
if (!file_exists($dbName)) {
    die("Could not find database file.");
}
$db = new PDO("odbc:DRIVER={Microsoft Access Driver (*.mdb)}; DBQ=$dbName; Uid=; Pwd=;");

$sql  = "SELECT * FROM product";
$result = $db->query($sql);
while ($row = $result->fetch())
{
    echo $row["pid"];
    echo $row["pname"];
 
}


?>

(2)how to insert form data to msaccess database table:

create a  folder   "ms "  inside your   C:\xampp\htdocs\  and keep your   msaccess file products.mdb    database file  and create a table  product with two columns (pid ,pname )
now your path for database file  will be   "C:\xampp\htdocs\ms\products.mdb"

(1)write code for insert.html file:

<form action="insert.php"  method="post">
pid<input type=text name=pid>
pname<input type=text name=pname>
<input type=submit name=submit value=submit>
</form>
(2)now write code for  insert.php file:

<?php
$dbName = $_SERVER["DOCUMENT_ROOT"] . "/ms/products.mdb";

echo  $_SERVER["DOCUMENT_ROOT"];
if (!file_exists($dbName)) {
    die("Could not find database file.");
}
$con = new PDO("odbc:DRIVER={Microsoft Access Driver (*.mdb)}; DBQ=$dbName; Uid=; Pwd=;");


$sql = "insert into product(pid,pname) values(:pid,:pname)";
$statement = $con->prepare($sql);
$statement->bindParam(':pid', $_POST['pid'], PDO::PARAM_INT);
$statement->bindParam(':pname', $_POST['pname'], PDO::PARAM_STR);

$result = $statement->execute();
if($result)
 echo "Inserted Successfully!";
else
 echo "Not Inserted";



?>


(3)NOW WRITE CODE FOR UPDATEING TABLE RECORD:

(1)write code for update.html file:

<form action="update.php"  method="post">
pid<input type=text name=pid>
pname<input type=text name=pname>
<input type=submit name=submit value=submit>
</form>

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

<?php
$dbName = $_SERVER["DOCUMENT_ROOT"] . "/ms/products.mdb";

echo  $_SERVER["DOCUMENT_ROOT"];
if (!file_exists($dbName)) {
    die("Could not find database file.");
}
$con = new PDO("odbc:DRIVER={Microsoft Access Driver (*.mdb)}; DBQ=$dbName; Uid=; Pwd=;");


$sql = "UPDATE product SET pname=:pname where pid=:pid";
$statement = $con->prepare($sql);
$statement->bindParam(':pid', $_POST['pid'], PDO::PARAM_INT);
$statement->bindParam(':pname', $_POST['pname'], PDO::PARAM_STR);

$result = $statement->execute();
if($result)
 echo "UPDATED Successfully!";
else
 echo "Not updated";

?>

(4)NOW WRITE CODE FOR DELETING RECORD FROM  TABLE OF MSACCESS:

(1)write code for  delete.html file:

<form action="delete.php"  method="post">
pid<input type=text name=pid>

<input type=submit name=submit value=submit>
</form>

(2)write code for delete.php file:

<?php
$dbName = $_SERVER["DOCUMENT_ROOT"] . "/ms/products.mdb";

echo  $_SERVER["DOCUMENT_ROOT"];
if (!file_exists($dbName)) {
    die("Could not find database file.");
}
$con = new PDO("odbc:DRIVER={Microsoft Access Driver (*.mdb)}; DBQ=$dbName; Uid=; Pwd=;");


$sql = "delete from product  where pid=:pid";
$statement = $con->prepare($sql);
$statement->bindParam(':pid', $_POST['pid'], PDO::PARAM_INT);

$result = $statement->execute();
if($result)
 echo "deleted Successfully!";
else
 echo "Not deleted";

?>

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.

3 comments:


  1. Hello,
    It is very useful content..I am looking for such type of content. Thanks for sharing.
    PHP Training Institute Chandigarh

    ReplyDelete
  2. It's interesting that many of the bloggers to  helped  clarify a few things for me as well as giving.Most of ideas can be nice content.The people to give them a good shake to get your point and across the command.
    PHP Training in Chennai

    ReplyDelete
  3. It is amazing and wonderful to visit your site.Thanks for sharing this information,this is useful to me...
    Android Training in Chennai
    Ios Training in Chennai

    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