Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Submit feedback
Contribute to GitLab
Sign in
Toggle navigation
P
PHP-MySQLi-Database-Class
Project
Project
Details
Activity
Releases
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Boards
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
Kulya
PHP-MySQLi-Database-Class
Commits
91beb078
Commit
91beb078
authored
Jun 28, 2016
by
Jonas
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Fixed up formatting + removed gitignore + added tests for testing the import functions
parent
dae696fd
Changes
3
Hide whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
68 additions
and
17 deletions
+68
-17
.gitignore
.gitignore
+0
-5
MysqliDb.php
MysqliDb.php
+7
-12
test.import.php
tests/dataimport/test.import.php
+61
-0
No files found.
.gitignore
deleted
100644 → 0
View file @
dae696fd
#Mac OS X files
.DS_Store
#Vim trash
*.swptests/csvimport/test.import.php
MysqliDb.php
View file @
91beb078
...
...
@@ -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
;
}
...
...
tests/dataimport/test.import.php
0 → 100644
View file @
91beb078
<?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
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment