php - Read urls-csv and insert them in a mysql -
i have create php script reads list of urls , insert them in mysql-database. problem inserts first line , stops.
<?php $conn=mysql_connect("my_servername","my_username","my_password") or die (mysql_error()); mysql_select_db("my_dbname") or die (mysql_error()); $url = array("url1.csv", "url2.csv", "url3.csv", . . . "url15.csv", ); for ($i=0; $i<15; $i++) { $url_go = file_get_contents($url[$i]); $z = array_filter(explode("\x0a",$url_go[$i])); $counter=0; foreach($z $k=>$v) { if($metr>2) { $y=( (explode(';',rtrim($v,";"))) ); $sql = 'insert `mysql_table_name` (name_of_column_1,name_of_column_2, name_of_column_3, name_of_column_4, name_of_column_5, name_of_column_6,name_of_column_7,name_of_column_8,name_of_column_9,name_of_column_10,name_of_column_11,name_of_column_12,name_of_column_13, name_of_column_14,name_of_column_15, name_of_column_16) values ('.$y[0].', '.$y[1].', '.$y[2].', '.$y[3].', '.$y[4].', '.$y[5].', '.$y[6].', '.$y[7].', '.$y[8].', '.$y[9].', '.$y[10].', '.$y[11].', '.$y[12].', '.$y[13].', '.$y[14].' , '.$y[15].')'; } $counter++; } } $result=mysql_query($sql) or die('query failed:' . mysql_error()); mysql_close($conn); ?>
database has been created navicat. urls in csv type.like table same columns columns of database dont want insert first 3 rows of csv-urls
your query execution needs within 2nd loop because $sql variable keeps getting overwritten , executed 1 time.
$sql = 'insert `mysql_table_name` (name_of_column_1,name_of_column_2, name_of_column_3, name_of_column_4, name_of_column_5, name_of_column_6,name_of_column_7,name_of_column_8,name_of_column_9,name_of_column_10,name_of_column_11,name_of_column_12,name_of_column_13, name_of_column_14,name_of_column_15, name_of_column_16) values ('.$y[0].', '.$y[1].', '.$y[2].', '.$y[3].', '.$y[4].', '.$y[5].', '.$y[6].', '.$y[7].', '.$y[8].', '.$y[9].', '.$y[10].', '.$y[11].', '.$y[12].', '.$y[13].', '.$y[14].' , '.$y[15].')'; mysql_query($sql) or die('query failed:' . mysql_error());
Comments
Post a Comment