Friday, March 29, 2013

copy files one folder to create dyanmic new folder using php


<?php
$ran=rand(125,2212);
copyfolder('bk', $ran);
function copyfolder($source, $destination)
{

       //Open the specified directory

       $directory = opendir($source);

       //Create the copy folder location

      if(!file_exists($destination)){
    mkdir($destination);
 }else{
  echo $destination." floder already exits";
  exit;
 }

       //Scan through the folder one file at a time


       while(($file = readdir($directory)) != false)
       {

              //Copy each individual file

              if(copy($source.'/'.$file,$destination.'/'.$file)){

 }

       }
 
 
$file = $destination.'/index.php';
// Open the file to get existing content
$current = file_get_contents($file);


// Append a new person to the file
$current .= "\nMage::run('$destination', 'website');\n";
// Write the contents back to the file
file_put_contents($file, $current);

}

?>

Thursday, March 28, 2013

transaction in mysql using php example

<?php
function begin()
{
mysql_query("BEGIN");
}

function commit()
{
mysql_query("COMMIT");
}

function rollback()
{
mysql_query("ROLLBACK");
}

mysql_connect("localhost","Dude1", "SuperSecret") or die(mysql_error());

mysql_select_db("bedrock") or die(mysql_error());

$query = "INSERT INTO employee (ssn,name,phone) values ('123-45-6789','Matt','1-800-555-1212')";

begin(); // transaction begins

$result = mysql_query($query);

if(!$result)
{
rollback(); // transaction rolls back
echo "transaction rolled back";
exit;
}
else
{
commit(); // transaction is committed
echo "Database transaction was successful";
}

?>