pdo_extension.php
<?php
$DBServer = 'localhost';
$DBUser = 'root';
$DBPass = '';
$DBName = 'db_webinarcruds';
$conn = new PDO("mysql:host=$DBServer;dbname=$DBName", "$DBUser", "$DBPass");
function getData($conn,$sql){
$rs = $conn->query( $sql );
while ( $row = $rs->fetch( PDO::FETCH_ASSOC ) ){
$ar[] =$row;
}
return $ar;
}
?>
$DBServer = 'localhost';
$DBUser = 'root';
$DBPass = '';
$DBName = 'db_webinarcruds';
$conn = new PDO("mysql:host=$DBServer;dbname=$DBName", "$DBUser", "$DBPass");
function getData($conn,$sql){
$rs = $conn->query( $sql );
while ( $row = $rs->fetch( PDO::FETCH_ASSOC ) ){
$ar[] =$row;
}
return $ar;
}
?>
latpdo.php
<?php
require_once"pdo_extension.php";
require_once"datatable.php";
?>
<h1>Koneksi Database PDO Extension</h1>
<table id="examplec" class="display" style="width:100%">
<thead>
<tr>
<th>IDKat</th>
<th>Nama Kategori</th>
<th>Deskripsi</th>
<th>Menu</th>
</tr>
</thead>
<tbody>
<?php
$sql="select * from `tb_kategori`";
$arr=getData($conn,$sql);
foreach($arr as $d) {
$id_kategori=$d["id_kategori"];
$nama_kategori=$d["nama_kategori"];
$deskripsi=$d["deskripsi"];
$deskripsi = wordwrap($deskripsi, 100, "<br />");
echo "<tr>
<td>$id_kategori</td>
<td>$nama_kategori</td>
<td><small>$deskripsi</small></td>
<td>
<button type='button' class='btn btn-primary'>Ubah</button>
|
<button type='button' class='btn btn-primary'>Hapus</button>
</td>
</tr> ";
}
?>
</tbody>
<tfoot>
<tr>
<th>IDKat</th>
<th>Nama Kategori</th>
<th>Deskripsi</th>
<th>Menu</th>
</tr>
</tfoot>
</table>
<?php
function getJum($conn,$sql){
$rs = $conn->prepare( $sql );
$rs->execute();
return $rs->columnCount();
}
function getJum0($conn,$sql){
$rs = $conn->query( $sql );
return $rs->columnCount();
}
function getField($conn,$sql){
$rs = $conn->query($sql);
$d = $rs->fetch( PDO::FETCH_ASSOC );
return $d;
}
function process($conn,$sql){
$rs = $conn->prepare($sql );
$rs->execute();
return $rs;
}
function getKategori($conn,$kode){
$kolom="nama_kategori";
$sql="select `$kolom` from `tb_kategori` where `id_kategori`='$kode'";
$stmt = $conn->query($sql);
$d = $stmt->fetch(PDO::FETCH_OBJ );
return $d->$kolom;
}
?>
require_once"pdo_extension.php";
require_once"datatable.php";
?>
<h1>Koneksi Database PDO Extension</h1>
<table id="examplec" class="display" style="width:100%">
<thead>
<tr>
<th>IDKat</th>
<th>Nama Kategori</th>
<th>Deskripsi</th>
<th>Menu</th>
</tr>
</thead>
<tbody>
<?php
$sql="select * from `tb_kategori`";
$arr=getData($conn,$sql);
foreach($arr as $d) {
$id_kategori=$d["id_kategori"];
$nama_kategori=$d["nama_kategori"];
$deskripsi=$d["deskripsi"];
$deskripsi = wordwrap($deskripsi, 100, "<br />");
echo "<tr>
<td>$id_kategori</td>
<td>$nama_kategori</td>
<td><small>$deskripsi</small></td>
<td>
<button type='button' class='btn btn-primary'>Ubah</button>
|
<button type='button' class='btn btn-primary'>Hapus</button>
</td>
</tr> ";
}
?>
</tbody>
<tfoot>
<tr>
<th>IDKat</th>
<th>Nama Kategori</th>
<th>Deskripsi</th>
<th>Menu</th>
</tr>
</tfoot>
</table>
<?php
function getJum($conn,$sql){
$rs = $conn->prepare( $sql );
$rs->execute();
return $rs->columnCount();
}
function getJum0($conn,$sql){
$rs = $conn->query( $sql );
return $rs->columnCount();
}
function getField($conn,$sql){
$rs = $conn->query($sql);
$d = $rs->fetch( PDO::FETCH_ASSOC );
return $d;
}
function process($conn,$sql){
$rs = $conn->prepare($sql );
$rs->execute();
return $rs;
}
function getKategori($conn,$kode){
$kolom="nama_kategori";
$sql="select `$kolom` from `tb_kategori` where `id_kategori`='$kode'";
$stmt = $conn->query($sql);
$d = $stmt->fetch(PDO::FETCH_OBJ );
return $d->$kolom;
}
?>
datatable.php
<script src="https://code.jquery.com/jquery-3.5.1.js"></script>
<script src="https://cdn.datatables.net/1.11.3/js/jquery.dataTables.min.js"></script>
<script>
$(document).ready(function() {
$('#examplec').DataTable();
} );
</script>
<link rel="stylesheet" href="https://cdn.datatables.net/1.11.3/css/jquery.dataTables.min.css">
Tidak ada komentar:
Posting Komentar