File "populateDB.php"

Full path: /var/www/html/xenioo_api/populateDB.php
File size: 2.16 KB B
MIME-type: text/x-php
Charset: utf-8

Download   Open   Edit   Advanced Editor   Back

<?php
error_reporting(E_ALL & ~E_NOTICE);
include_once('configuration.php');


// read spreadsheet
$url = 'https://docs.google.com/spreadsheets/d/1dmpKRiWNOonfuGElfneXFvmxFHWvNpSx8vU9WlXDO9o/gviz/tq';


$ch = curl_init();
curl_setopt($ch, CURLOPT_URL, $url);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
curl_setopt($ch, CURLOPT_FOLLOWLOCATION, true);
$response = curl_exec($ch);
curl_close($ch);


$response = str_replace("/*O_o*/","",$response);
$response = str_replace("google.visualization.Query.setResponse(","",$response);
$response = str_replace(");","",$response);



// Decode JSON data to PHP associative array
$obj = json_decode($response, true);

$rows = $obj["table"]["rows"];

$total_rows = count($rows);

//echo $total_rows;

for($i=0; $i<$total_rows; $i++){
	$temp_row = $rows[$i]['c'];
	
	$t_id 		= $temp_row[0]['v'];
	$t_cid 		= $temp_row[1]['v'];
	$t_name 	= $temp_row[2]['v'];
	$t_sname 	= $temp_row[3]['v'];
	$t_mphone 	= $temp_row[4]['v'];
	$t_phone 	= $temp_row[5]['v'];
	$t_email 	= $temp_row[6]['v'];
	$t_astatus 	= $temp_row[7]['v'];
	$t_debt 	= $temp_row[8]['v'];
	$t_sstatus 	= $temp_row[9]['v'];
	
	
	/*echo $t_id . "<br>";
	echo $t_cid . "<br>";
	echo $t_name . "<br>";
	echo $t_sname . "<br>";
	echo $t_mphone . "<br>";
	echo $t_phone . "<br>";
	echo $t_email . "<br>";
	echo $t_astatus . "<br>";
	echo $t_debt . "<br>";
	echo $t_sstatus . "<br>";*/
	
	$sql = "INSERT INTO DB_Clients VALUES('$t_id', '$t_cid', '$t_name', '$t_sname', '$t_mphone', '$t_phone', '$t_email', '$t_astatus', '$t_debt', '$t_sstatus');";
	
	if (mysqli_query($DBcon, $sql)) {
		echo "New record added successfully";
	} else {
		//echo "Error: " . $sql . "<br>" . mysqli_error($DBcon);
		//echo "<br>";
		
		$sql = "UPDATE DB_Clients SET `Client ID` = '$t_cid', Name = '$t_name', Surename = '$t_sname', `Mobile Phone` = '$t_mphone', Phone = '$t_phone', Email = '$t_email', 
		`Account Status` = '$t_astatus', Debt = '$t_debt', `Service Status` = '$t_sstatus' WHERE ID = '$t_id'";
		//echo $sql;
	
		if ($DBcon->query($sql) === TRUE) {
			echo "Record updated successfully" . "<br>";
		} 
	}
	

}

echo "<br>Database Updated";

?>