Skip to content

Instantly share code, notes, and snippets.

/import.php Secret
Created Dec 22, 2017

Embed
What would you like to do?
Import.php
<?php
##########################################################################
#
# Conexión a la base de datos
#
##########################################################################
$server = "localhost";
$user = "user";
$password = "password";
$dbname = "database";
try {
//Conectar
$db = new PDO("mysql:host=$server;dbname=$dbname", $user, $password);
$db->exec('SET NAMES utf8');
// Establecer el nivel de errores a EXCEPTION
$db->setAttribute(PDO::ATTR_ERRMODE, PDO::ERRMODE_EXCEPTION);
} catch (PDOException $e){
echo "Error: " . $e->getMessage();
}
##########################################################################
$json = file_get_contents('technicians.json');
$data = json_decode($json, true);
foreach ($data as $row) {
$sentencia = $db->prepare("INSERT INTO technicians (technician_id, name_tech, username_tech, pass_tech, role) VALUES (:technician_id, :name_tech, :username_tech, :pass_tech, :role)");
$sentencia->bindParam(':technician_id', $technician_id);
$sentencia->bindParam(':name_tech', $name_tech);
$sentencia->bindParam(':username_tech', $username_tech);
$sentencia->bindParam(':pass_tech', $pass_tech);
$sentencia->bindParam(':role', $role);
$technician_id = $row['technician_id'];
$name_tech = $row['name_tech'];
$username_tech = $row['username_tech'];
$pass_tech = $row['pass_tech'];
$role = $row['role'];
$sentencia->execute();
}
##########################################################################
$json = file_get_contents('customers.json');
$data = json_decode($json, true);
foreach ($data as $row) {
$sentencia = $db->prepare("INSERT INTO customers (customer_id, customer, business_name, administrative, email, phone, mobile_phone) VALUES (:customer_id, :customer, :business_name, :administrative, :email, :phone, :mobile_phone)");
$sentencia->bindParam(':customer_id', $customer_id);
$sentencia->bindParam(':customer', $customer);
$sentencia->bindParam(':business_name', $business_name);
$sentencia->bindParam(':administrative', $administrative);
$sentencia->bindParam(':email', $email);
$sentencia->bindParam(':phone', $phone);
$sentencia->bindParam(':mobile_phone', $mobile_phone);
$customer_id = $row['customer_id'];
$customer = $row['customer'];
$business_name = $row['business_name'];
$administrative = $row['administrative'];
$email = $row['email'];
$phone = $row['phone'];
$mobile_phone = $row['mobile_phone'];
$sentencia->execute();
}
##########################################################################
$json = file_get_contents('tasks.json');
$data = json_decode($json, true);
foreach ($data as $row) {
$sentencia = $db->prepare("INSERT INTO tasks (task_id, created_by, support_by, customer_id, request_of, description, status_task, start_date, finish_date) VALUES (:task_id, :created_by, :support_by, :customer_id, :request_of, :description, :status_task, :start_date, :finish_date)");
$sentencia->bindParam(':task_id', $task_id);
$sentencia->bindParam(':created_by', $created_by);
$sentencia->bindParam(':support_by', $support_by);
$sentencia->bindParam(':customer_id', $customer_id);
$sentencia->bindParam(':request_of', $request_of);
$sentencia->bindParam(':description', $description);
$sentencia->bindParam(':status_task', $status_task);
$sentencia->bindParam(':start_date', $start_date);
$sentencia->bindParam(':finish_date', $finish_date);
$task_id = $row['task_id'];
$created_by = $row['created_by'];
$support_by = $row['support_by'];
$customer_id = $row['customer_id'];
$request_of = $row['request_of'];
$description = $row['description'];
$status_task = $row['status_task'];
$start_date = $row['start_date'];
$finish_date = $row['finish_date'];
$sentencia->execute();
}
##########################################################################
?>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.