domingo, 26 de agosto de 2018

Export Data from MySQL to CSV Using PHP


Export Data from MySQL to CSV Using PHP
Written by Yogesh Koli
Export MySQL data to CSV
A step-by-step guide to export data to CSV from MySQL using PHP
It is a basic task for any application that needs a reporting feature to CSV; here I am going to explain how to generate a CSV file from the MySQL records.
Let’s get started:

Step 1 – Create Sample Database and Required Table along with the data:

Create Database table with sample records, here I am going to use a users table, which is going to have users details, go ahead and use following SQL statements to create table and insert the records. (Note: you can skip this step if you have your existing database tables)
IMAGE : Users Table Structure
Users Table Structure
Existing records from mysql database
Existing Mysql Records to Export

Step 2 Create PHP to MySQL Database Connection Script:

Create Database configuration file, which is going help us to connect to MySQL from PHP file.

Step 3 – Add Sample Index Page to List out the Records:

Create index.php file and list records.

index-file

Step 4- Exporting MySQL Data to CSV file PHP Script:

Create export.php file to export data from Mysql to CSV.
button-click
Click OK to export the data to CSV and your file get’s downloaded
file-get-donwloaded

If you check download file, you get records listed, as showing below:
Records from CSV files
Records from CSV files
We are done, you can download the complete source for reference use following links to download or checkout live demo.

martes, 14 de agosto de 2018

searching values on array

search if values of an array are present on other array
<?php
$arr1=array("From","source","NT");

$os = array("Mac", "NT", "Irix", "Linux");


foreach($arr1 as $value){
if (in_array($value,$os)) {
    echo "Found $value <br>";
}

else {
echo " Value  $value not found<br>";
}

}

?>


<?php
function version

function removeheader($header,$arr) {


foreach($header as $value){
if (in_array($value,$arr)) {
    echo "Found $value <br>";
}

else {
echo " Value  $value not found<br>";
}

}


}


removeheader($arr1,$os);

?>

sábado, 4 de agosto de 2018

php mailer

1) install mailer

  composer require phpmailer/phpmailer


2) run the code  php send.php ambiorixg12@gmail.com


<?php
/**
 * This example shows sending a message using a local sendmail binary.
 */
//Import the PHPMailer class into the global namespace
use PHPMailer\PHPMailer\PHPMailer;
require './vendor/autoload.php';
//Create a new PHPMailer instance
$mail = new PHPMailer;
// Set PHPMailer to use the sendmail transport
$mail->isSendmail();
//Set who the message is to be sent from
$mail->setFrom('from@example.com', 'First Last');
//Set an alternative reply-to address
$mail->addReplyTo('replyto@example.com', 'First Last');
//Set who the message is to be sent to
$mail->addAddress("$argv[1]", 'Ambiorix Rodriguez');
//Set the subject line
$mail->Subject = 'PHPMailer sendmail test';
//Read an HTML message body from an external file, convert referenced images to embedded,
//convert HTML into a basic plain-text alternative body
//$mail->msgHTML(file_get_contents('contents.html'), __DIR__);
//Replace the plain text body with one created manually
//$mail->AltBody = 'This is a plain-text message body';
//plain text body
 $mail->Body='This is a plain-text message body';

//Attach an image file
//$mail->addAttachment('images/phpmailer_mini.png');
//send the message, check for errors
if (!$mail->send()) {
    echo "Mailer Error: " . $mail->ErrorInfo;
} else {
    echo "Message sent!";
}
?>
https://github.com/PHPMailer/PHPMailer
https://github.com/PHPMailer/PHPMailer/tree/master/examples