Import large mysql database using mysql command prompt

Freedom Web Blog

Click your wamp server icon then look for MYSQL > MSQL Console then run it.
console

If you dont have password, just hit enter and type :

mysql> use database_name;
mysql> source location_of_your_file;
If you have password, you will promt to enter a password. Enter you password first then type:

mysql> use database_name;
mysql> source location_of_your_file;
location_of_your_file should look like C:/mydb.sql

for desktop my location is like :: C:/Users/Zaheer/Desktop/db.sql/db.sql
so the command is mysql>source C:/Users/Zaheer/Desktop/db.sql/db.sql;

This kind of importing sql dump is very helpful for BIG SQL FILE.

I copied my file mydb.sq to directory C: .It should be capital C: in order to run

and that’s it.

View original post

Convert html to pdf using tcpdf in php

Convert html to pdf using tcpdf in php

Download tcpdf and include require file.

include (‘tcpdf/tcpdf.php’);

Extend default class of tcpdf If you want edit or modify pdf

class MYPDF extends TCPDF {
//Page header
public function Header() {
$headerData = $this->getHeaderData();
$this->SetFont(‘helvetica’, ‘B’, 10);
$this->writeHTML($headerData[‘string’]);
}
}

$pdf = new MYPDF(PDF_PAGE_ORIENTATION, PDF_UNIT, PDF_PAGE_FORMAT, true, ‘UTF-8’, false); //Default for UTF-8 unicode
//$pdf = new MYPDF(PDF_PAGE_ORIENTATION, PDF_UNIT, PDF_PAGE_FORMAT, false, ‘ISO-8859-1′, false); // set unicode to ISO-8859-1 so special chars like æ, ø, å will work.
$pdf->SetCreator(PDF_CREATOR);
// set default header data
$pdf->setHeaderData($ln=”, $lw=0, $ht=”, $hs='<table id=”head” cellpadding=”1″ cellspacing=”1″ style=”text-align:center;”><tr><td>All Category Report</td></tr></table>’, $tc=array(0,0,0), $lc=array(0,0,0));
// set header and footer fonts
$pdf->setHeaderFont(Array(PDF_FONT_NAME_MAIN, ”, PDF_FONT_SIZE_MAIN));
$pdf->setFooterFont(Array(PDF_FONT_NAME_DATA, ”, PDF_FONT_SIZE_DATA));
// set default monospaced font
$pdf->SetDefaultMonospacedFont(PDF_FONT_MONOSPACED);
$pdf->SetAutoPageBreak(TRUE, PDF_MARGIN_BOTTOM);
// set document information
$pdf->AddPage();

Create table structure html and apply css in style.

$html ='<style>
th{border:0.5px solid #C0C0C0;background-color:rgb(44,126,193); font-size: 9pt;text-align: center;color:#FFFFFF;font-weight:bold;}
td{ vertical-align: middle;padding-top:5px;border:0.5px solid #C0C0C0;padding:5pt;color:#000000;background-color:#FFFFFF;font-size: 8pt;text-align: center;}
</style>
<table>
<thead>
<tr nobr=”true”><th>Id</th><th>Name</th></tr>
</thead><tbody>
<tr nobr=”true”>
<td>1</td>
<td>Senta</td>
</tr>
</tbody>
</table>’;

Finally write html to pdf to store in this folder create new pdf folder

$pdf->writeHTML($html, true, false, false, false, ”);
$pdf->lastPage();
ob_end_clean();
$fname = ‘test-‘.date(“d-m-Y-H-i-s”).’.pdf’; // filename test
$pdf->output(dirname(dirname(__FILE__)).”/pdf/test-“.date(“d-m-Y-H-i-s”).’.pdf’, ‘I’); // pdf view
//$pdf->Output(dirname(dirname(__FILE__)).”/pdf/test-“.date(“d-m-Y-H-i-s”).’.pdf’,’F’); // save in pdf folder

Make sure All content of code under <?php ?> tag and remove whitespace before closing tag of php.

Html to convert pdf save in to folder and Mail

Html to convert pdf save in to folder and Mail

Here Example of html table structure to convert to pdf using jspdf.

<table id= “xyz”><thead><tr><th>id</th></tr></thead>
<tbody><tr><td>1</td></tbody></table>

You can add style tag inline and give css to it.

Thereafter Include require Js file

https://ajax.googleapis.com/ajax/libs/jquery/1.8.3/jquery.min.js
http://html2canvas.js
http://from_html.js
http://jspdf.plugin.autotable.js

var doc = new jsPDF(‘l’, ‘pt’, ‘a4’);
var specialElementHandlers = {
‘#xyz’: function(element, renderer){
return true;
}};
var table = document.getElementById(“xyz”);
var res = doc.autoTableHtmlToJson(table, true);
doc.autoTable(res.columns, res.data, {
startY: 60,
tableWidth: ‘auto’,
columnWidth: ‘auto’,
styles: {
overflow: ‘linebreak’
},
beforePageContent: function(data) {
doc.text(“New Pdf”, 40, 30);}
});
var pdf =doc.output(); //returns raw body of resulting PDF returned as a string as per the plugin documentation.
var data = new FormData();
data.append(“data” , pdf);
var xhr = new XMLHttpRequest();
xhr.open( ‘post’, ‘test.php’, true ); //Post to php Script to save to server
xhr.send(data);

After That Create new php file to post data on it and using phpmailer you can attached and mail. eg:test.php

<?php
require_once “../../PHPMailer/class.phpmailer.php”; // Download phpmailer
if(!empty($_POST[‘data’])){
$data = $_POST[‘data’];
$fname = ‘newpdf-‘.date(‘d-m-Y’).’.pdf’; // name the file
$file = fopen(“../pdf/” .$fname, ‘w’); // open the file path
fwrite($file, $data); //save data
fclose($file);
$bodytext = ‘Please Find PDF’;
$email = new PHPMailer();
$email->From = ‘xxx@xyz.com’;
$email->FromName = ‘My first pdf’;
$email->Subject = $file;
$email->Body = $bodytext;
$email->AddAddress( ‘xyz@abc.com’ );
//$email->AddAddress(‘person2@domain.com’, ‘Person Two’);
//$file_to_attach = $_SERVER[‘DOCUMENT_ROOT’].’/front/pdf’;
$email->AddAttachment(‘../pdf/’.$fname );

return $email->Send();
} else {
echo “No Data Sent”;
}
?>

How To Use Cache In Magento

In this section we will see how to use cache in our custom modules. Suppose you have a custom module and wanted to save some data in magento cache, lets see how to do it.

Saving Data To Cache

$data = array(1,2,3,4); //any data which you want to save to cache $id = 'my_mod_id'; //unique id for your cache data $tags = array('collection'); //cache tags will be explain later in detail $lifetime = false; //false means infinity, or you can specify number of seconds $priority = 8; // number between 0-9, used by few backend cache models Mage::app()->saveCache($data,$id,$tags,$lifetime,$priority); Retrieving Data Mage::app()->loadCache($id);

Deleting Cache Mage::app()->removeCache($id);

Checking If Cache Is Enabled Mage::app()->useCache('collection'); //check if cache group is enabled or not

above are some basic caching function we can use in magento.

Custom Sending emails in magento

you can put this script in controller or any event of user

<?php

$email_to = 'xyz@gmail.com';

$receiveName = 'xyz';

$vars = data of user

$template_id = "New email"; //Name of email template
$email_template = Mage::getModel('core/email_template')->loadByCode($template_id);  //load templa
$email_template->setSenderName(Mage::getStoreConfig('trans_email/ident_sales/name'));
$email_template->setSenderEmail(Mage::getStoreConfig('trans_email/ident_support/email'));

$email_template->send($email_to,$receiveName, $vars);

 

?>

Display Most popular Posts In WordPress

Add code in your theme where ever you want the popular 5 posts to be displayed.

<ul>
    <?php $pc = new WP_Query('orderby=comment_count&posts_per_page=5'); 
		
      while ($pc->have_posts()) : $pc->the_post(); ?>
		<li><a href="<?php the_permalink(); ?>" title="<?php the_title(); ?>"><?php the_title(); ?></a>
		<p>Posted by <strong><?php the_author() ?></strong> with <?php comments_popup_link('No Comments;', '1 Comment', '% Comments'); ?></p></li>
      <?php endwhile; ?>
</ul>

Display special priced products on your Magento homepage

Step 1: Open your homepage CMS page and click on the content tab. Paste the following:

{{block type="catalog/product" name="home.new" alias="product" template="catalog/product/special.phtml"}}

 

Step 2: First of all this is the code were that we’re going to be using to do this.

<?php
Mage::getSingleton('core/session', array('name' => 'frontend'));
$_productCollection = Mage::getResourceModel('catalogsearch/advanced_collection')
->addAttributeToSelect(Mage::getSingleton('catalog/config')->getProductAttributes())
->addMinimalPrice()
->addStoreFilter();

Mage::getSingleton('catalog/product_status')->addVisibleFilterToCollection($_productCollection);
Mage::getSingleton('catalog/product_visibility')->addVisibleInSearchFilterToCollection($_productCollection);

$todayDate = date('m/d/y');
$tomorrow = mktime(0, 0, 0, date('m'), date('d'), date('y'));
$tomorrowDate = date('m/d/y', $tomorrow);

$_productCollection->addAttributeToFilter('special_from_date', array('date' => true, 'to' => $todayDate))
->addAttributeToFilter('special_to_date', array('or'=> array(
0 => array('date' => true, 'from' => $tomorrowDate),
1 => array('is' => new Zend_Db_Expr('null')))
), 'left');
?>
<div class="specials_block">
<div class="page-title"><h2><?php echo $this->__('Specials') ?></h2></div>
<?php  $_collectionSize = $_productCollection->count();  ?>

<ul class="products-grid-new row">

<?php  $i=0; foreach($_productCollection as $_product): ?>
<?php $i++; if($i!=5){?>
<li class="item span3<?php if(($i-1)%$_columnCount==0): ?> first<?php elseif($i%$_columnCount==0): ?> last<?php endif; ?>">
<h3 class="product-name"><a href="<?php echo $_product->getProductUrl() ?>" title="<?php echo $this->htmlEscape($_product->getName()) ?>"><span></span><?php echo $this->htmlEscape($_product->getName()) ?></a></h3>
<a href="<?php echo $_product->getProductUrl() ?>" title="<?php echo $this->htmlEscape($_product->getName()) ?>" class="product-image non-mobile-img"><img src="<?php echo $this->helper('catalog/image')->init($_product, 'small_image')->resize(270, 217) ?>" alt="<?php echo $this->htmlEscape($_product->getName()) ?>" /></a>
<div class="block_holder">

<span class="price">
<?php echo $this->getPriceHtml($_product, true, '-new') ?></span>

<div class="descr"><?php echo $_product->getShortDescription() ?></div>
<div class="actions">
<a href="<?php echo $this->helper('checkout/cart')->getAddUrl($_product) ?> " class="icon-shopping-cart"></a>
<a href="<?php echo $_product->getProductUrl() ?>" class="icon-info-sign"></a>
<?php if ($this->helper('wishlist')->isAllow()) : ?>
<a href="<?php  echo $this->helper('wishlist')->getAddUrl($_product) ?>" class="icon-star-empty"></a>
<?php endif; ?>
<?php $_compareUrl=$this->helper('catalog/product_compare')->getAddUrl($_product) ?>
<a href="<?php echo $_compareUrl ?>" class="icon-retweet"></a>

</div>
</div>
</li>
<?php } else {break;}?>
<?php endforeach ?>
</ul>
</div>


You can then paste this into a file and name it specials.phtml and save it into your frontend template folder catalog/product.