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

  • SEARCH
  • Home
  • 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 8219251
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 7, 20262026-06-07T13:05:24+00:00 2026-06-07T13:05:24+00:00

Possible Duplicate: Import CSV to mysql Right I need some help with this: I

  • 0

Possible Duplicate:
Import CSV to mysql

Right I need some help with this:

I am trying to import a .csv file into a mysql database using php, rather than doing it manually through phpmyadmin.

This is the code I have at the moment:

if($_REQUEST['func'] == "iid"){
    $db->conn = new mysqli(DB_SERVER, DB_USER, DB_PASSWORD, DB_NAME) or 
                      die('There was a problem connecting to the database.');
    $csv = $_POST['csv-file'];
    $path = $csv;
    $row = 1;
    if (($handle = fopen($path, "r")) !== FALSE) {
        while (($data = fgetcsv($handle, 1000, ";")) !== FALSE) {
            $row++;
            $data_entries[] = $data ;

        }
        fclose($handle);
    }
    // this you'll have to expand
    foreach($data_entries as $line){
        $sql = $db->conn->prepare('INSERT INTO `bd_results`');

        $db->execute($line);
    }
}

However I get the following error:

Fatal error: Call to undefined method stdClass::execute() in /homepages/19/d372249701/htdocs/business-sites/bowlplex-doubles-new/admin/scores.php on line 44

For reference I am using this code taken from: Here

I am not well versed in the $db->conn business I’m used to mysql_connect!! so any help would be appreciated.

  • 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-07T13:05:26+00:00Added an answer on June 7, 2026 at 1:05 pm

    Try this simple one.

    if (($handle = fopen("google.csv", "r")) !== FALSE) {
        while (($data = fgetcsv($handle, 1000, ",")) !== FALSE) {
            $db->conn->query("INSERT INTO values('" . implode('\',\'', $data) . "');");
        }
        fclose($handle);
    }
    

    Your script might also need to add quotes to the CSV values if they don’t have quotes already. If you’ll be needing to deal with quotes and all in your CSV files, I recommend you look at my blog post at http://www.fusionswift.com/2012/07/php-import-csv-to-mysql/

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Possible Duplicate: Best practice: Import mySQL file in PHP; split queries How to import
I have some CSV data files that I want to import into mySQL. I
Possible Duplicate: Open a file in the proper encoding automatically my code: import csv
Is it possible to import csv data into mysql and automatically create the column
Possible Duplicate: CSV File Imports in .Net In .net, is there a standard library
Possible Duplicate: How to import contact from gmail using java I want to import
Possible Duplicate: from . import x using __import__ ? How does one do the
Possible Duplicate: Why won't this generic java code compile? Given the following code: import
Possible Duplicate: How to change database settings for a deployed war file? OK I
Possible Duplicate: Import XML to SQL using C# I just downloaded about 3000 XML

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.