1<?php
2$query = <<<eof
3 LOAD DATA INFILE '$fileName'
4 INTO TABLE tableName
5 FIELDS TERMINATED BY '|' OPTIONALLY ENCLOSED BY '"'
6 LINES TERMINATED BY '\n'
7 IGNORE 1 LINES
8 (field1,field2,field3,etc)
9eof;
10
11$db->query($query);
12?>
13
1<?php
2/*
3* iTech Empires: Export Data from MySQL to CSV Script
4* Version: 1.0.0
5* Page: Index
6*/
7
8// Database Connection
9require("db_connection.php");
10
11// List Users
12$query = "SELECT * FROM users";
13if (!$result = mysqli_query($con, $query)) {
14 exit(mysqli_error($con));
15}
16
17if (mysqli_num_rows($result) > 0) {
18 $number = 1;
19 $users = '<table class="table table-bordered">
20 <tr>
21 <th>No.</th>
22 <th>First Name</th>
23 <th>Last Name</th>
24 <th>Email</th>
25 </tr>
26 ';
27 while ($row = mysqli_fetch_assoc($result)) {
28 $users .= '<tr>
29 <td>'.$number.'</td>
30 <td>'.$row['first_name'].'</td>
31 <td>'.$row['last_name'].'</td>
32 <td>'.$row['email'].'</td>
33 </tr>';
34 $number++;
35 }
36 $users .= '</table>';
37}
38
39?>
40<!doctype html>
41<html lang="en">
42<head>
43 <meta charset="UTF-8">
44 <title>Export Data from MySQL to CSV Tutorial | iTech Empires</title>
45 <!-- Bootstrap CSS File -->
46 <link rel="stylesheet" type="text/css" href="bootstrap/css/bootstrap.min.css"/>
47</head>
48<body>
49<div class="container">
50 <!-- Header -->
51 <div class="row">
52 <div class="col-md-12">
53 <h2>Export Data from MySQL to CSV</h2>
54 </div>
55 </div>
56 <!-- /Header -->
57
58 <!-- Content -->
59 <div class="form-group">
60 <?php echo $users ?>
61 </div>
62 <div class="form-group">
63 <button onclick="Export()" class="btn btn-primary">Export to CSV File</button>
64 </div>
65 <!-- /Content -->
66
67 <script>
68 function Export()
69 {
70 var conf = confirm("Export users to CSV?");
71 if(conf == true)
72 {
73 window.open("export.php", '_blank');
74 }
75 }
76 </script>
77</div>
78</body>
79</html>
80
81