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
5ff94ccc
Commit
5ff94ccc
authored
Jun 28, 2016
by
Jonas
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Added loadXML and tests
parent
487c4618
Changes
1
Show whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
59 additions
and
0 deletions
+59
-0
MysqliDb.php
MysqliDb.php
+59
-0
No files found.
MysqliDb.php
View file @
5ff94ccc
...
...
@@ -970,6 +970,65 @@ class MysqliDb
return
$success
;
}
public
function
loadXML
(
$importTable
,
$importFile
,
$importSettings
=
Array
(
"linesToIgnore"
=>
0
))
{
// Define default success var
$success
=
false
;
// We have to check if the file exists
if
(
file_exists
(
$importFile
))
{
// Create default values
$ignoreLines
=
0
;
// Default 0
// Check the import settings
if
(
gettype
(
$importSettings
)
==
"array"
)
{
if
(
isset
(
$importSettings
[
"linesToIgnore"
]))
{
$ignoreLines
=
$importSettings
[
"linesToIgnore"
];
}
}
// Add the prefix to the import table
$table
=
self
::
$prefix
.
$importTable
;
// Add 1 more slash to every slash so maria will interpret it as a path
$importFile
=
str_replace
(
"
\\
"
,
"
\\\\
"
,
$importFile
);
// 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"
]);
}
// IGNORE LINES
$sqlSyntax
.=
sprintf
(
' IGNORE %d LINES'
,
$ignoreLines
);
// Exceute the query unprepared because LOAD XML only works with unprepared statements.
$result
=
$this
->
queryUnprepared
(
$sqlSyntax
);
// Are there rows modified?
if
(
$result
)
{
$success
=
true
;
}
// Something went wrong
else
{
$success
=
false
;
}
}
else
{
// Throw an exception
throw
new
Exception
(
"importXML -> importFile "
.
$importFile
.
" does not exists!"
);
}
// Let the user know if the import failed / succeeded
return
$success
;
}
/**
* This method allows you to specify multiple (method chaining optional) ORDER BY statements for SQL queries.
*
...
...
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