Sorry nich agak ngawur di Isi...
Jangan percaya ma PT. MIS INTERNATIOAL udah banyak yang usaha buat ditipeng, termasuk gw....
Jumat, 18 April 2008
BackUp Restore (2)
Ini dia function buat nge-Restorenya....
function restore_this($from_file)
{
copy($from_file,"backup\\i".$from_file);
$fp = fopen("backup\\$from_file", "r");
while(!feof($fp)){
$x = fgets($fp, 4096);
mysql_query($x);
}
fclose($fp);
}
function restore_this($from_file)
{
copy($from_file,"backup\\i".$from_file);
$fp = fopen("backup\\$from_file", "r");
while(!feof($fp)){
$x = fgets($fp, 4096);
mysql_query($x);
}
fclose($fp);
}
Senin, 14 April 2008
BackUp Restore PHP ???
Ok kali ini saya kasih Script tentang Back-up Restore pada PHP. Pada prinsipnya, skrip ini menuliskan seluruh data pada database ke teks file :
function back_up_this($into_file){
$into_file = fopen("backup\\".$into_file,"w+");
$i=0;
$x=0;
$counter=0;
$qry=mysql_query("show tables") or die(mysql_error());
$list_table="";
while($row=mysql_fetch_array($qry)){
$list_table.="$row[0]#";
}
$list_table=substr($list_table,0,strlen($list_table)-1);
$sTable=explode("#",$list_table);
$cBackUp=count($sTable);
for($counter=0;$counter<$cBackUp;$counter++)
{
$cn=mysql_connect($_COOKIE["SERVER"],$_COOKIE["MY_USER"],$_COOKIE["MY_PASS"]);
mysql_select_db($_COOKIE["MY_DATABASE"],$cn);
$user_query=mysql_query(" Select * From ".$sTable[$counter]) or die ($user_query);
$field_define=mysql_list_fields($_COOKIE["MY_DATABASE"],$sTable[$counter]);
$field_count=mysql_num_fields($field_define);
for($i=0;$i<>
while($R=mysql_fetch_row($user_query)){
$X = "Insert Into $sTable[$counter] Values(";
for($x=0;$x<$field_count;$x++){
if ($x==($field_count-1)){
$X .="'$R[$x]'";
}else{
$X .= "'$R[$x]',";
}
}
$X .= ")\n";
fwrite($into_file,$X);
}
}
}
fclose($into_file);
}
trus gimana cara gunain-nya ??
nama file: test.php
if(isset($_POST["tNama"]))
{
back_up_this("$_POST[tNama].php");
}
dengan catatan sediain satu folder nama-nya: backup
function back_up_this($into_file){
$into_file = fopen("backup\\".$into_file,"w+");
$i=0;
$x=0;
$counter=0;
$qry=mysql_query("show tables") or die(mysql_error());
$list_table="";
while($row=mysql_fetch_array($qry)){
$list_table.="$row[0]#";
}
$list_table=substr($list_table,0,strlen($list_table)-1);
$sTable=explode("#",$list_table);
$cBackUp=count($sTable);
for($counter=0;$counter<$cBackUp;$counter++)
{
$cn=mysql_connect($_COOKIE["SERVER"],$_COOKIE["MY_USER"],$_COOKIE["MY_PASS"]);
mysql_select_db($_COOKIE["MY_DATABASE"],$cn);
$user_query=mysql_query(" Select * From ".$sTable[$counter]) or die ($user_query);
$field_define=mysql_list_fields($_COOKIE["MY_DATABASE"],$sTable[$counter]);
$field_count=mysql_num_fields($field_define);
for($i=0;$i<>
while($R=mysql_fetch_row($user_query)){
$X = "Insert Into $sTable[$counter] Values(";
for($x=0;$x<$field_count;$x++){
if ($x==($field_count-1)){
$X .="'$R[$x]'";
}else{
$X .= "'$R[$x]',";
}
}
$X .= ")\n";
fwrite($into_file,$X);
}
}
}
fclose($into_file);
}
trus gimana cara gunain-nya ??
nama file: test.php
if(isset($_POST["tNama"]))
{
back_up_this("$_POST[tNama].php");
}
dengan catatan sediain satu folder nama-nya: backup
Minggu, 13 April 2008
No Otomatis ........
Banyak banget yang tanya tentang Nomor Otomatis di PHP, padahal tinggal cari di mas GOOGLE. tapi ini dunia Open Source Man.....
Coba script ini :
function cuhe_num($field,$table,$key,$Parse,$Digit_Count)
{
$NOL="0";
$Q = mysql_query("Select $field from $table where $key like '$Parse%' order by $key DESC") or die(mysql_error()."Select $field from $table where $key like '$Parse%' order by $key DESC");
$N = mysql_affected_rows();
$counter=2;
if($N==0)
{
while($counter < $Digit_Count)
{
$NOL="0".$NOL;
$counter++;
}
return $Parse.$NOL."1";
}
else
{
$R = mysql_fetch_row($Q);
$K = sprintf("%d",substr($R[0],-$Digit_Count));
$K = $K + 1;
$L = $K;
while(strlen($L)!=$Digit_Count)
{
$L = "0".$L;
}
return $Parse.$L;
}
}
?>
gimana cara pake nya????
nih !!!!
echo cuhe_num("id","table","id","Cuhe",5);
ntar tampilan-nya :
Cuhe00001
Coba script ini :
function cuhe_num($field,$table,$key,$Parse,$Digit_Count)
{
$NOL="0";
$Q = mysql_query("Select $field from $table where $key like '$Parse%' order by $key DESC") or die(mysql_error()."Select $field from $table where $key like '$Parse%' order by $key DESC");
$N = mysql_affected_rows();
$counter=2;
if($N==0)
{
while($counter < $Digit_Count)
{
$NOL="0".$NOL;
$counter++;
}
return $Parse.$NOL."1";
}
else
{
$R = mysql_fetch_row($Q);
$K = sprintf("%d",substr($R[0],-$Digit_Count));
$K = $K + 1;
$L = $K;
while(strlen($L)!=$Digit_Count)
{
$L = "0".$L;
}
return $Parse.$L;
}
}
?>
gimana cara pake nya????
nih !!!!
echo cuhe_num("id","table","id","Cuhe",5);
ntar tampilan-nya :
Cuhe00001
Langganan:
Postingan (Atom)