Connect.php
<?php
class database{
private $host;
private $user;
private
$password;
private $db;
function
_construct($a,$b,$c,$d){
$this->host=$a;
$this->user=$b;
$this->password=$c;
$this->db=$d;
}
function
sambung(){
mysql_connect("localhost","root","");
$k=mysql_select_db("akademik");
}
function
tambahdata(){
$query="insert
into mahasiswa values('144360534','Ddy','jl.glagh','dicky@gmail.com')";
$hasil=mysql_query($query);
if($hasil)
echo
"data sukses di tambahkan";
else
echo
"error.. gagal di tambahkan";
$tampil="select
* from mahasiswa";
$tampildata=mysql_query($tampil);
echo
"
<table
border='1'>
<tr>
<td>no</td>
<td>NIM</td>
<td>NAMA</td>
<td>ALAMAT</td>
";
$i=1;
while($data=@mysql_fetch_array($tampildata)){
echo"<tr>
<td>
Ini data ke- ".$i ."</td>
<td>
".$data ['nim']."</td>
<td>
".$data ['nama']."</td>
<td>
".$data ['alamat']."</td>
<td>
".$data ['email']."</td>
</tr>
";
$i++;
}
}
}
?>
|
Index.php
<?php
mysql_connect("localhost","root","");
mysql_select_db("akademik");
$query="insert
into mahasiswa
values('1400018142','Dicky','jl.glagah','dicky@gmail.com')";
$hasil=mysql_query($query);
if($hasil)
echo "berhasil
bro...";
else
echo "wah ada masalah
nih";
$tampil="select
* from mahasiswa";
$tampildata=mysql_query($tampil);
$i=1;
while($data=mysql_fetch_array($tampildata)){
echo "Ini data ke-
".$i ."<br/>";
echo $data
['nim']."<br/>";
echo $data
['nama']."<br/>";
echo $data
['alamat']."<br/>";
echo $data
['email']."<br/><br/>";
$i++;
}
?>
|
Panggil.php
<?php
include
'connect.php';
$host="localhost";
$user="root";
$password="";
$db="akademik";
$vardb=new
database($host,$user,$password,$db);
$vardb->sambung();
$vardb->tambahdata();
?>
|
Sign up here with your email
ConversionConversion EmoticonEmoticon