<?php
error_reporting(-1);

class Database {

	private $user = 'root';
	private $pass = '';
	private $dbName = 'test_data';

	public function __construct() {
		$this->db = new PDO('mysql:host=localhost;dbname=' . $this->dbName, $this->user, $this->pass);
	}

	function insertBatch($table, $data) {

		$tableColNamesArray = array();
		$tableColParamsArray = array();
		$tableColValuesArray = array();


		foreach ($data as $num => $dataRow) {
			
			$oneRowValuesArray = array();

			foreach ($dataRow as $tableColName => $value) {
				if ($num == 1) {
					$tableColNamesArray[] = $tableColName;
					$tableColParamsArray[] = '?';
 				}
				$oneRowValuesArray[] = $value;

			}
			$tableColValuesArray[] = $oneRowValuesArray;
		}

		$query = 'INSERT INTO '. $table .' (' . implode(', ', $tableColNamesArray) . ') VALUES (' . implode(', ', $tableColParamsArray) . ')';

		// var_dump($tableColValuesArray);
		// exit;

		$this->db->beginTransaction();
		$stmt = $this->db->prepare($query);

		foreach($tableColValuesArray as $insertRow) {
			//var_dump($insertRow);

			$stmt->execute($insertRow);
		}
		$this->db->commit();
		print_r($this->db->errorInfo()); 
	}

}