Using an Access Database with PHP

Using an Access Database with PHP - Hallo sahabat Tutorials, Pada Artikel yang anda baca kali ini dengan judul Using an Access Database with PHP, kami telah mempersiapkan artikel ini dengan baik untuk anda baca dan ambil informasi didalamnya. mudah-mudahan isi postingan yang kami tulis ini dapat anda pahami. baiklah, selamat membaca.

Judul : Using an Access Database with PHP
link : Using an Access Database with PHP

Baca juga


Using an Access Database with PHP

(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";

?>


Demikianlah Artikel Using an Access Database with PHP

Sekianlah artikel Using an Access Database with PHP kali ini, mudah-mudahan bisa memberi manfaat untuk anda semua. baiklah, sampai jumpa di postingan artikel lainnya.

Anda sekarang membaca artikel Using an Access Database with PHP dengan alamat link https://othereffect.blogspot.com/2016/11/using-access-database-with-php.html

0 Response to "Using an Access Database with PHP"

Post a Comment