Tuesday, 8 July 2014

How to get Mysql Database Backup Using PHP

If you want to get backup of all tables in your database or specific table in those database .
I think this script will help you for getting database backup.

Here is the example of Database Backup PHP Script :

<?php function backup_db() { $host="localhost"; $uname="database_username"; $pass="database_password"; $database = "databasename";  $return = ""; $connection=mysqli_connect($host,$uname,$pass,$database);  /* Store All Table name in an Array */ $allTables = array(); $result = mysqli_query($connection,'SHOW TABLES'); while($row = mysqli_fetch_row($result)){ $allTables[] = $row[0]; } foreach($allTables as $table){ $result = mysqli_query($connection,'SELECT * FROM '.$table); $num_fields = mysqli_num_fields($result); $return.= 'DROP TABLE IF EXISTS '.$table.';'; $row2 = mysqli_fetch_row(mysqli_query($connection,'SHOW CREATE TABLE '.$table)); $return.= "\n\n".$row2[1].";\n\n"; for ($i = 0; $i < $num_fields; $i++) { while($row = mysqli_fetch_row($result)){   $return.= 'INSERT INTO '.$table.' VALUES('; for($j=0; $j<$num_fields; $j++){   $row[$j] = addslashes($row[$j]);   $row[$j] = str_replace("\n","\\n",$row[$j]);   if (isset($row[$j])) { $return.= '"'.$row[$j].'"' ; }    else { $return.= '""'; }   if ($j<($num_fields-1)) { $return.= ','; } }   $return.= ");\n"; } } $return.="\n\n"; } // Create Backup Folder $folder = 'e:/DB_Backup/'; // I am getting database backup on my E driver. if (!is_dir($folder)) mkdir($folder, 0777, true); chmod($folder, 0777); date_default_timezone_set('Asia/Kolkata'); $date = date('m-d-Y-H-i-s', time());  $filename = $folder."db-backup-".$date;  $handle = fopen($filename.'.sql','w+'); fwrite($handle,$return); fclose($handle); } // Call the function backup_db();?>

Tuesday, 11 February 2014

Working with Jquery datatable with dynamic data using PHP and Mysql

DataTables is a powerful jQuery plugin for creating table listings and adding interactions to them. It provides searching, sorting and pagination without any configuration. In this article we’ll go through the basics of DataTable and how to use some of the advanced features.

STEP 1 :- Create Database and Table.

We take Example : we create table user in which username and email_id is shown.




STEP 2 :- Now Create Connection in your PHP Page and Connect database with this table .

HERE is the Complete Code of PHP Page : 


<?php
$con = mysqli_connect('localhost','root','','test');
$sqlselect = mysqli_query($con,"SELECT * FROM User");
?>
<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8">
<link rel="shortcut icon" type="image/ico" href="http://www.datatables.net/favicon.ico">

<title>DataTables example - Zero configuration</title>
<link rel="stylesheet" type="text/css" href="media/css/jquery.dataTables.css">
<link rel="stylesheet" type="text/css" href="resources/syntax/shCore.css">
<link rel="stylesheet" type="text/css" href="resources/demo.css">
<style type="text/css" class="init">

</style>
<script type="text/javascript" language="javascript" src="media/js/jquery.js"></script>
<script type="text/javascript" language="javascript" src="media/js/jquery.dataTables.js"></script>
<script type="text/javascript" language="javascript" src="resources/syntax/shCore.js"></script>
<script type="text/javascript" language="javascript" src="resources/demo.js"></script>
<script type="text/javascript" language="javascript" class="init">


$(document).ready(function() {
$('#example').dataTable();
} );


</script>
</head>

<body class="dt-example">
<div class="container">
<section>
<h1>DataTables example <span>- Dynamic with PHP and MYSQL</span></h1>

<div class="info">
<p>DataTables has most features enabled by default, so all you need to do to use it with your own
tables is to call the construction function.</p>

<p>Searching, ordering, paging etc goodness will be immediately added to the table, as shown in this
example.</p>
</div>

<table id="example" class="display" cellspacing="0" width="100%">
<thead>
<tr>
<th>ID</th>
<th>USERNAME</th>
<th>EMAIL-ID</th>
</tr>
</thead>

<tfoot>
<tr>
<th>ID</th>
<th>USERNAME</th>
<th>EMAIL-ID</th>
</tr>
</tfoot>

<tbody>
<?php
while($rowselect = mysqli_fetch_array($sqlselect))
{
echo"<tr>
<td>".$rowselect['ID']."</td>
<td>".$rowselect['usernam']."</td>
<td>".$rowselect['email']."</td>
</tr>";
}
?>
</tbody>
</table>
</div>
</body>
</html>
You Can Download It From Here : Click Here

For Any Query Please Write a comment !!

Thanks












Sunday, 1 December 2013

Send e-mail in PHP

For Sending Mail in PHP their is inbuilt funtion to send e-mails in php but this function only works in server where you can send your e-mail with your server e-mails.

mail(to,subject,message,headers,parameters)

Here is running example of mail function in php

<?php
if(isset($_POST['btn_email']))
{
$email_to = "sender-email";
        $email_subject = "Subject";
$name=$_POST['name'];
$email=$_POST['email'];
$sub=$_POST['Subject'];
$messagenew=$_POST['message'];
$email_message = "Name: ".$name."\n";
    $email_message .= "Email: ".$email."\n";
    $email_message .= "Subject: ".$sub."\n";
    $email_message .= "Message: ".$messagenew."\n";
// create email headers
$headers = 'From: '.$email."\r\n".
'Reply-To: '.$email."\r\n" .
'X-Mailer: PHP/' . phpversion();
@mail($email_to, $email_subject, $email_message, $headers);  
 
echo"<script>alert('Thank you for contacting us. We will be in touch with you very soon.');</script>";
}
?>
<form action="Contact.php" method="post" class="std" enctype="multipart/form-data">
<h1 style='color:black'>Send a message</h1>
<p class="text select">
<label for="id_order">Name</label>
<input type="text" name="name" id="name" value="" />
</p>
<p class="text select">
<label for="id_order">Subject</label>
<input type="text" name="Subject" id="Subject" value="" />
</p>
<p class="text">
   <label for="email">E-mail address</label>
<input type="text" id="email" name="email" value="" />
</p>
<p class="textarea">
<label for="message">Message</label>
<textarea id="message" name="message" ></textarea>
</p>
<p class="submit">
<input type="submit" name="btn_email" id="btn_email" value="Send" class="button_large" onclick="$(this).hide();" />
</p>
</form>
You Can Download It From Here : Click Here

For Any Query Please Write a comment !!

Thanks