public static function getMysqli() { if (self::$mysqli === null) { try { // throw exceptions instead of PHP errors mysqli_report(MYSQLI_REPORT_STRICT); // connect! self::$mysqli = new mysqli("localhost", "user", "mY15463sql", "EvoApi"); } catch (mysqli_sql_exception $error) { throw new mysqli_sql_exception("Unable to connect to mySQL", 0, $error); } } return self::$mysqli; }
while (!feof($handle)) { $line_of_data = fgets($handle); //gets data from file one line at a time $line_of_data = trim($line_of_data); //trims the data $fileData[] = str_getcsv($line_of_data, ",", "\""); //breaks the line up into pieces that the array can store } //var_dump($fileData); $data = $fileData; //var_dump($data); //close file reading stream fclose($handle); fwrite($log, "Close Log --------------------------------------------------------------------------------" . PHP_EOL . PHP_EOL); fclose($log); $mysqli = MysqliConfiguration::getMysqli(); // create query template $query = "TRUNCATE TABLE clients"; $statement = $mysqli->prepare($query); // execute the statement if ($statement->execute() === false) { throw new mysqli_sql_exception("Unable to execute mySQL statement Truncate"); } // handle degenerate cases if (gettype($mysqli) !== "object" || get_class($mysqli) !== "mysqli") { throw new mysqli_sql_exception("input is not a mysqli object"); } foreach ($data as $line) { // create query template $query = "INSERT INTO clients(clientId, clientName, clientNumber) VALUES(?, ?, ?)"; $statement = $mysqli->prepare($query);