Commit 91beb078 authored by Jonas's avatar Jonas

Fixed up formatting + removed gitignore + added tests for testing the import functions

parent dae696fd
#Mac OS X files
.DS_Store
#Vim trash
*.swptests/csvimport/test.import.php
......@@ -903,11 +903,7 @@ class MysqliDb
* @author Jonas Barascu (Noneatme)
* @param string $importTable The database table where the data will be imported into.
* @param string $importFile The file to be imported. Please use double backslashes \\ and make sure you
* use an absolute path.
* @param string $terminateCharField The char which will be used to separate the data in a row.
* @param string $terminateCharLine The char which marks the EOL. (PHP_EOL is also possible)
* @param string $ignoreLines The ammount of lines to ignore. Useful if your #0 row marks the data structure.
*
* @param string $importSettings An Array defining the import settings as described in the README.md
* @return boolean
*/
public function loadData($importTable, $importFile, $importSettings =
......@@ -987,8 +983,10 @@ class MysqliDb
* Check out the LOAD XML syntax for your MySQL server.
*
* @author Jonas Barascu
* @param string $importTable The table in which the data will be imported to.
* @param string $importFile The file which contains the .XML data.
* @param string $importTable The table in which the data will be imported to.
* @param string $importFile The file which contains the .XML data.
* @param string $importSettings An Array defining the import settings as described in the README.md
*
* @return boolean Returns true if the import succeeded, false if it failed.
*/
public function loadXML($importTable, $importFile, $importSettings = Array("linesToIgnore" => 0))
......@@ -1003,7 +1001,6 @@ class MysqliDb
// Check the import settings
if(gettype($importSettings) == "array") {
if(isset($importSettings["linesToIgnore"])) {
$ignoreLines = $importSettings["linesToIgnore"];
}
......@@ -1018,7 +1015,6 @@ class MysqliDb
// Build SQL Syntax
$sqlSyntax = sprintf('LOAD XML INFILE \'%s\' INTO TABLE %s',
$importFile, $table);
// FIELDS
if(isset($importSettings["rowTag"])) {
$sqlSyntax .= sprintf(' ROWS IDENTIFIED BY \'%s\'', $importSettings["rowTag"]);
......@@ -1158,11 +1154,10 @@ class MysqliDb
}
}
}
else
{
else{
// Build the table prefix
$table = self::$prefix . $table;
// Build the query
$this->_query = "LOCK TABLES ".$table." ".$this->_tableLockMethod;
}
......
<?php
// TEST HAS BEEN DONE USING PHP 7.0
// Basic Stuff
error_reporting (E_ALL|E_STRICT);
require_once ("../../MysqliDb.php");
require_once ("../../dbObject.php");
// Create database context
$db = new MysqliDb ('localdev', 'noneatme', '12345', 'db_test');
// Import CSV
echo "Testing: File Not Found", PHP_EOL;
// File not Found
goto test_filenotfound;
// File Not Found Test
test_filenotfound:
try
{
// It should throw an exception
$db->loadData("users", "datanew.csv");
}
catch(Exception $e)
{
echo "Test 1 Succeeded!", PHP_EOL;
// goto newtest
goto test_import1;
}
test_import1:
{
try
{
// Import the CSV
$db->loadData("users", // Table
"D:\\DEV\\git\\PHP-MySQLi-Database-Class\\tests\\dataimport\\data.csv",
Array("fieldEnclosure" => '', "lineStarting" => ''));
echo "Test 2 Succeeded!", PHP_EOL;
goto test_import2;
}
catch(Exception $e)
{
echo($e);
}
}
test_import2:
{
try
{
$db->setLockMethod("WRITE")->lock(array("users", "log"));
$db->loadXML("users",
"D:\\DEV\\git\\PHP-MySQLi-Database-Class\\tests\\dataimport\\data.xml");
echo "Test 3 Succeeded!", PHP_EOL;
$db->unlock();
}
catch(Exception $e)
{
echo($e);
}
}
\ No newline at end of file
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment