2019-04-06 12:04:49 +00:00
|
|
|
<?php
|
|
|
|
/**
|
|
|
|
* @file database.mysql.cmd.php
|
|
|
|
* @date 2019-04-06
|
|
|
|
* @auther Go Namhyeon <gnh1201@gmail.com>
|
|
|
|
* @brief MySQL(MariaDB) command line driver
|
|
|
|
*/
|
|
|
|
|
2019-09-16 04:28:35 +00:00
|
|
|
if(!check_function_exists("exec_db_mysql_cmd_query")) {
|
2019-05-20 08:19:05 +00:00
|
|
|
function exec_db_mysql_cmd_query($sql, $bind) {
|
|
|
|
$result = false;
|
|
|
|
$config = get_config();
|
2019-04-06 12:04:49 +00:00
|
|
|
|
2019-05-20 08:19:05 +00:00
|
|
|
$args = array("mysql");
|
|
|
|
$sql = get_db_binded_sql($sql, $bind);
|
2019-04-06 12:04:49 +00:00
|
|
|
|
2019-05-20 08:19:05 +00:00
|
|
|
if(loadHelper("exectool")) {
|
2019-09-16 04:28:11 +00:00
|
|
|
$args[] = sprintf("-u'%s'", $config['db_username']);
|
|
|
|
$args[] = sprintf("-p'%s'", $config['db_password']);
|
|
|
|
$args[] = sprintf("-h'%s'", $config['db_host']);
|
2019-09-16 02:40:48 +00:00
|
|
|
$args[] = "-s"; // --slient
|
2019-09-16 04:28:11 +00:00
|
|
|
$args[] = sprintf("-D'%s'", $config['db_name']);
|
|
|
|
$args[] = sprintf("-e'%s'", make_safe_argument($sql));
|
2019-04-24 11:33:43 +00:00
|
|
|
|
2019-09-16 02:40:48 +00:00
|
|
|
$cmd = implode(" ", $args);
|
2019-05-20 08:19:05 +00:00
|
|
|
$result = exec_command($cmd);
|
|
|
|
}
|
2019-04-24 11:33:43 +00:00
|
|
|
|
2019-05-20 08:19:05 +00:00
|
|
|
return $result;
|
|
|
|
}
|
2019-04-06 12:04:49 +00:00
|
|
|
}
|
2019-09-16 01:51:09 +00:00
|
|
|
|
2019-09-16 04:28:35 +00:00
|
|
|
if(!check_function_exists("exec_db_mysql_cmd_fetch_all")) {
|
2019-09-16 02:40:48 +00:00
|
|
|
function exec_db_mysql_cmd_fetch_all($sql, $bind) {
|
|
|
|
$result = false;
|
2019-09-16 04:17:12 +00:00
|
|
|
|
2019-09-16 02:40:48 +00:00
|
|
|
$tsvData = exec_db_mysql_cmd_query($sql, $bind);
|
|
|
|
$lines = explode(DOC_EOL, $tsvData);
|
|
|
|
$rows = array();
|
2019-09-16 04:31:44 +00:00
|
|
|
|
|
|
|
if(check_function_exists("str_getcsv")) {
|
|
|
|
foreach($lines as $line) {
|
|
|
|
$rows[] = str_getcsv($line, "\t");
|
|
|
|
}
|
|
|
|
} else {
|
|
|
|
foreach($lines as $line) {
|
|
|
|
$rows[] = explode("\t", $line);
|
|
|
|
}
|
2019-09-16 02:40:48 +00:00
|
|
|
}
|
2019-09-16 04:28:11 +00:00
|
|
|
|
2019-09-16 02:40:48 +00:00
|
|
|
if(count($rows) > 0) {
|
|
|
|
$result = $rows;
|
|
|
|
}
|
2019-09-16 04:17:12 +00:00
|
|
|
|
2019-09-16 02:40:48 +00:00
|
|
|
return $result;
|
2019-09-16 01:51:09 +00:00
|
|
|
}
|
|
|
|
}
|