Skip to content

Instantly share code, notes, and snippets.

@Vijaysinh
Created December 18, 2021 14:15
Show Gist options
  • Save Vijaysinh/61da1f6450150f7f07cc8a1ae58c189f to your computer and use it in GitHub Desktop.
Save Vijaysinh/61da1f6450150f7f07cc8a1ae58c189f to your computer and use it in GitHub Desktop.
insertGoogleAdsLocation
<?php
$csv = "geotargets-2021-11-01.csv";
define('DB_USER', 'root');
define('DB_PASS', '');
define('DB', 'adwords');
define('DB_HOST','localhost');
$bd = mysqli_connect(DB_HOST,DB_USER,DB_PASS,DB) or die("Could not connect database");
$handle = fopen($csv, "r");
for ($i = 0; $row = fgetcsv($handle ); ++$i) {
if($i == 0){
continue;
}
if($row[5] == 'Postal Code' || $row[5] == 'State' || $row[5] == 'Country' || $row[5] =='City'){
echo $sql = "INSERT INTO `location`(id,`text`, `CanonicalName`, `Target`) VALUES ({$row[0]},'{$row[1]}','{$row[2]}','{$row[5]}')";
mysqli_query($bd,$sql);
echo "<br>";
}
}
fclose($handle);
?>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment