Thursday, January 28, 2016

How to import sql backup using php script ( Using PHP/PDO ).

Make a Copy of Tables using  PHP / PDO


session_start();
$con = include("config.php");
$filename = 'path_to_file/backup_db.sql';
// Temporary variable, used to store current query
$templine = '';
// Read in entire file
$lines    = file($filename);
// Loop through each line
foreach ($lines as $line) {
    // Skip it if it's a comment
    if (substr($line, 0, 2) == '--' || $line == '')
        continue;
 
    // Add this line to the current segment
    $templine .= $line;
    // If it has a semicolon at the end, it's the end of the query
    if (substr(trim($line), -1, 1) == ';') {
        $query    = $con->prepare($templine);         // Perform the query
        $done     = $query->execute();
        $templine = ''; //free up memory
    }
}
echo "Tables imported successfully";




Monday, January 4, 2016

How to connect mysqli with php using PDO?

$host = "localhost";
$username = "root";
$password = "";
 $conn = new PDO("mysql:host=$host;dbname=myDB", $username, $password);
// set the PDO error mode to exception
$conn->setAttribute(PDO::ATTR_ERRMODE, PDO::ERRMODE_EXCEPTION);
echo "Connected successfully";

Saturday, December 19, 2015

how to create RSS Feed


<?php echo '<?xml version="1.0" encoding="UTF-8" ?>';?>
 <rss version="2.0">
    <channel>
        <title>BhojpuriTrain.com</title>
        <description>Free Bhojpuri song download</description>
        <link>http://bhojpuritrain.com</link>      
       
        <item>
            <title>BhojpuriTrain.com</title>
            <description>Watch PK2 Comedy Short Film directed by SRikanth Reddy PK2 is a hilarious Hindi short film spoof</description>
            <link>http://bhojpuritrain.com/player.php?v=LHu3_CXEdJY</link>
            <pubDate>Thu, 01 Jan 1970 00:00:00 +0000</pubDate>  
        </item>
       
        <item>
            <title>A 2 year old cute kid Dugu answering the quote answer</title>
            <description>Must watch how this cute boy answering</description>
            <link>http://bhojpuritrain.com/player.php?v=od0YNytKPCo</link>
            <pubDate>Thu, 01 Jan 1970 00:00:00 +0000</pubDate>  
        </item>
                       
        <item>
            <title>a very cute dance by village boy</title>
            <description>must see how a little kid dancing</description>
            <link>http://bhojpuritrain.com/player.php?v=didoFn8Erf0</link>
            <pubDate>Thu, 01 Jan 1970 00:00:00 +0000</pubDate>  
        </item>      
       
    </channel>
</rss>