How to get data from .CSV file using php & store it into Mysql database

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • mukeshpatil
    New Member
    • Sep 2006
    • 2

    How to get data from .CSV file using php & store it into Mysql database

    How to get data from .CSV file using php & store it into Mysql database

    I want to read data from two different .CSV files using php & How to store it into Mysql Database tables

    Please help me to do this.
  • ronverdonk
    Recognized Expert Specialist
    • Jul 2006
    • 4259

    #2
    There is a code snippet at http://codewalkers.com/seecode/175.html that you could (maybe after some changes) use for your purpose.

    Ronald :cool:

    Comment

    • mukeshpatil
      New Member
      • Sep 2006
      • 2

      #3
      Originally posted by ronverdonk
      There is a code snippet at http://codewalkers.com/seecode/175.html that you could (maybe after some changes) use for your purpose.

      Ronald :cool:

      Thanks
      this code is very useful for me.

      but i want the code for reading data from two files & import it into mysql table
      Plese give me the PHP code for this. & also i want the code for the php page is run daily at once automatically.
      please help me to do this.

      thanks

      Comment

      • chumma
        New Member
        • Feb 2007
        • 4

        #4
        Originally posted by mukeshpatil
        How to get data from .CSV file using php & store it into Mysql database

        I want to read data from two different .CSV files using php & How to store it into Mysql Database tables

        Please help me to do this.

        Just try this at 1ce
        <?php
        $row = 1;
        $handle = fopen("filename .csv", "r");
        while (($data = fgetcsv($handle , 1000, ",")) !== FALSE) {
        $num = count($data);
        echo "<p> $num fields in line $row: <br /></p>\n";
        $row++;
        for ($c=0; $c < $num; $c++) {
        echo $data[$c] . "<br />\n";
        }
        }
        fclose($handle) ;
        ?>

        Comment

        • chumma
          New Member
          • Feb 2007
          • 4

          #5
          Originally posted by mukeshpatil
          How to get data from .CSV file using php & store it into Mysql database

          I want to read data from two different .CSV files using php & How to store it into Mysql Database tables

          Please help me to do this.
          Here it is My Sample Codings, Itz Working....

          <?php
          $conn=mysql_con nect("localhost ","root","" ) or die("unable to connect localhost".mysq l_error());
          $db=mysql_selec t_db("mysql_db_ name",$conn) or die("unable to select db name");

          $file=fopen("Fi lename.csv","r" );
          while(($var=fge tcsv($file,1000 ,","))!==FAL SE)
          {
          $var1=$var[0];
          print_r($var);
          $ro=mysql_query ("select username from user where username='$var1 '");
          $ro1= mysql_num_rows( $ro);
          echo $ro1;

          if($ro1<1)
          mysql_query("in sert into user(username,p assword,age,com pany) values('$var[0]','$var[1]','$var[2]','$var[3]')");
          }
          fclose($file);

          ?>

          Comment

          • Abdullah Baki

            #6
            Thanks a lot

            Comment

            • jeya1985
              New Member
              • Mar 2012
              • 4

              #7
              hi

              Originally posted by ronverdonk
              There is a code snippet at http://codewalkers.com/seecode/175.html that you could (maybe after some changes) use for your purpose.

              Ronald :cool:

              i want this code but the link was not working

              Comment

              • jeya1985
                New Member
                • Mar 2012
                • 4

                #8
                How to get data from .CSV file using php & store it into Mysql database

                I want to read data from single .CSV files using php & How to store it into Mysql Database tables

                Please help me .

                Comment

                Working...