PHP Classes

File: index.php

Recommend this page to a friend!
  Classes of Albert Rosa   CSV2SQL_AR   index.php   Download  
File: index.php
Role: Example script
Content type: text/plain
Description: This is the index page
Generate SQL from data imported CSV files
Author: By
Last change:
Date: 12 years ago
Size: 4,341 bytes


Class file image Download

 * This is the form we will be using to upload the csv file to convert to sql
$error = null;
$text = null;
$success = false;
$table = true;
$insert = true;
$tableName = 'information';
$_FILES['file']['name'] != null)
$table = true;
$table = false;
$insert = true;
$insert = false;
$tableName = $_POST['tableName'];
$_FILES['file']['tmp_name'] != null)
$success = true;
$target_path = $_FILES['file']['tmp_name'] . '.csv';
move_uploaded_file($_FILES['file']['tmp_name'], $target_path))
$csvsql = new CSV2SQL($target_path, $table, $insert , $tableName);
$text = $csvsql->getSql();
             echo (
'Error uploading');
//here we will be using the file version of class
$error = 'THERE is an Error with the CSV2SQL';
$_POST['tableName'] && $_FILES['file']['name'] == null)
$error = "Please add a file in order to process";

         <title> | CSV to SQL</title>
         <meta name="author" content="Albert Rosa"/>
         <meta name="description" content="This is where I will be using csv files to be converted to sql files" />
         <meta name="keywords" content="Albert, Rosa, CSV, SQL, database, Mysql"/>
         <link href="/screen.css" media="screen" type="text/css" rel="stylesheet" />
         <style type="text/css">
             /** ADD RESET **/
             div.container {width:800px; background-color: #cdcdcd; margin-top:15px;}
             div.header{ background-color: #ddd;height:50px;padding:5px;}
             div.links {float:right; margin-right: 10px;}
             div.footer {padding:10px;}
             ul li {float:right;}
         <div class="container">
             <div class="header">
                 <div class="links">
                         <li><a href="" title="Albert Rosa">Albert Rosa</a></li>
                         <li><a href="" title="Albert Rosa : Blog">Blog</a> | </li>
                         <li><a href="" title="Albert Rosa : MTA Demo">MTA DEMO</a> | </li>
                 <div class="title"><h1>CSV 2 SQL</h1></div>
                 <div style="clear:both;"></div>
             <div class="content">
                    This is a form for converting CSV files to SQL.
                    This came about while my development of <a href="" title="Zend MTA Google Repo"> Zend Mta</a>
                    Please Note: The max file size allowed to be processed is <span class="red">5MB</span>. If the file is larger it will try to process but it will time out and run out of memory. So best case is to split the CSV file into multiple files placing the header columns on the top of each file.
                <? if($error != null):?>
<div class="error"><?= $error ?></div>
                <? endif; ?>

                <? if($success): ?>
<div class="success">Successfully submitted Form</div>
                <? endif;?>

                <form method="post" enctype="multipart/form-data">
                    <legend>CSV TO SQL</legend>
                        <dd><input type="file" name="file" id="file"/></dd>
                        <dt>Table Name:</dt>
                        <dd><input type="text" name="tableName" value="<?= $tableName ?>" /></dd>
                            <input type="checkbox" value="1" name="create" id="create" checked="checked" /> Create Table <br/>
                            <input type="checkbox" value="1" name="insert" id="insert" checked="checked" /> Insert Statements<br/>
                        <dd><input type="submit" value="Create SQL"/></dd>
                <?php if($success):?>
                    <p>Here is your Create and/or Insert Statements</p>
                        <dd><textarea class="textarea"><?= $text ?></textarea></dd>
                <?php endif; ?>
</div> <!-- end of content -->
             <div class="footer">
                 &copy; 2010 <a href="" title="Albert Rosa">Albert Rosa</a>
         </div> <!-- end of container -->