Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • Home
  • SEARCH
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8326765
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 9, 20262026-06-09T00:52:37+00:00 2026-06-09T00:52:37+00:00

I have created a data-structure in Mysql with table name(CSV filename) and field names(CSV

  • 0

I have created a data-structure in Mysql with table name(CSV filename) and field names(CSV column names).

Right now I am importing the data from csv to Mysql table successfully Where as I am hard-coding csv file name and field name in script. How to dynamical fetch bec I have manny csv files to import into mysql.

<?php
include "db.php";
$filename = "C:\REQ\Status.csv";
if (($handle = fopen($filename, 'r')) !== FALSE)
     while (($data = fgetcsv($handle, 1000, ",")) !== FALSE)
     {
       print_r($data);
       $import="INSERT into status(status) values('$data[1]')";
       mysql_query($import) or die(mysql_error());

     }
 fclose($handle);

?>    
  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-09T00:52:39+00:00Added an answer on June 9, 2026 at 12:52 am

    I have implement this code and it is tested code. I think it is very use full

    You have follow some rule:-

    1.your csv file according to database table name (ex: db table name is users then csv should be users.csv)

    2.Your csv file’s first row should be db table fields name (ex: Id, name etc) after the start your data entry

    3.you can download data source class from :- http://code.google.com/p/php-csv-parser/
    because i have require below the code: require_once ‘CSV/DataSource.php’;

    <?php
    ini_set('memory_limit','512M');
    $dbhost = "localhost";
    $dbname = "excel_import";
    $dbuser = "root";
    $dbpass = "";
    
    $conn=mysql_connect ($dbhost, $dbuser, $dbpass) or die ("I cannot connect to the database because: " . mysql_error());
    mysql_select_db($dbname) or die("Unable to select database because: " . mysql_error());
    
    
    require_once 'CSV/DataSource.php';
    
    
    $filename = "users.csv";
    $ext = explode(".",$filename);
    $path = "uploads/".$filename;
    
    $dbtable = $ext[0];
    
    import_csv($dbtable, $path);
    
    
    function import_csv($dbtable, $csv_file_name_with_path)
    {
        $csv = new File_CSV_DataSource;
        $csv->load($csv_file_name_with_path);
    
        $csvData = $csv->connect();
    
        $res='';
        foreach($csvData  as $key)
        {
            $myKey ='';
            $myVal='';
            foreach($key as $k=>$v)
            {
                $myKey .=$k.',';
                $myVal .="'".$v."',";
              }
    
            $myKey = substr($myKey, 0, -1);
            $myVal = substr($myVal, 0, -1); 
            $query="insert into ".$dbtable." ($myKey)values($myVal)";
            $res=  mysql_query($query);
    
        }
    
        if($res ==1)
        {
    
                    echo "record successfully Import.";
    
        }else{
    
                    echo "record not successfully Import.";
        }
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have a data structure created using read.csv() of dimensions 130, 395. I am
I have a table that was created using this mysql statement below. CREATE TABLE
I have the following data structure and data: CREATE TABLE `parent` ( `id` int(11)
I have mysql table with the following structure. All records are static and only
If I have a requirement to create a data structure that has the following
I have some data and need to create a json file with this structure
I have created data sources from my objects in my project, some of which
I have created a Data Access Layer using .NET. Everywhere that I update a
I have created a data base that comes in an installer that runs as
I have created a Dynamic Data site against an Entity Framework Model I have

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.