Server : Apache System : Linux iZ2vcgyutqttsd1p850kl8Z 3.10.0-1160.92.1.el7.x86_64 #1 SMP Tue Jun 20 11:48:01 UTC 2023 x86_64 User : www ( 1000) PHP Version : 5.6.40 Disable Function : passthru,exec,system,putenv,chroot,chgrp,chown,shell_exec,popen,proc_open,pcntl_exec,ini_alter,ini_restore,dl,openlog,syslog,readlink,symlink,popepassthru,pcntl_alarm,pcntl_fork,pcntl_waitpid,pcntl_wait,pcntl_wifexited,pcntl_wifstopped,pcntl_wifsignaled,pcntl_wifcontinued,pcntl_wexitstatus,pcntl_wtermsig,pcntl_wstopsig,pcntl_signal,pcntl_signal_dispatch,pcntl_get_last_error,pcntl_strerror,pcntl_sigprocmask,pcntl_sigwaitinfo,pcntl_sigtimedwait,pcntl_exec,pcntl_getpriority,pcntl_setpriority,imap_open,apache_setenv Directory : /www/wwwroot/saimikebio.com/mobile/include/kernel/library/ |
<?php // +---------------------------------------------------------------------- // | EcTouch [ 专注移动电商: 商创网络科技 ] // +---------------------------------------------------------------------- // | Copyright (c) 2014 http://ectouch.cn All rights reserved. // +---------------------------------------------------------------------- // | Licensed ( http://www.apache.org/licenses/LICENSE-2.0 ) // +---------------------------------------------------------------------- // | Author: EcTouch Team <zhong@ecmoban.com> (QQ: 2880175560) // +---------------------------------------------------------------------- //数据库安装类,用于导入mysql数据库文件 class Install { /* 参数: $sql_path:sql文件路径; $old_prefix:原表前缀; $new_prefix:新表前缀; $separator:分隔符 参数可为";\n"或";\r\n"或";\r" */ static public function mysql($sql_path, $old_prefix = "", $new_prefix = "", $separator = ";\n") { $commenter = array('#', '--'); //判断文件是否存在 if (!file_exists($sql_path)) return false; $content = file_get_contents($sql_path); //读取sql文件 $content = str_replace(array($old_prefix, "\r"), array($new_prefix, "\n"), $content); //替换前缀 //通过sql语法的语句分割符进行分割 $segment = explode($separator, trim($content)); //去掉注释和多余的空行 $data = array(); foreach ($segment as $statement) { $sentence = explode("\n", $statement); $newStatement = array(); foreach ($sentence as $subSentence) { if ('' != trim($subSentence)) { //判断是会否是注释 $isComment = false; foreach ($commenter as $comer) { if (preg_match("/^(" . $comer . ")/is", trim($subSentence))) { $isComment = true; break; } } //如果不是注释,则认为是sql语句 if (!$isComment) $newStatement[] = $subSentence; } } $data[] = $newStatement; } //组合sql语句 foreach ($data as $statement) { $newStmt = ''; foreach ($statement as $sentence) { $newStmt = $newStmt . trim($sentence) . "\n"; } if (!empty($newStmt)) { $result[] = $newStmt; } } return $result; } } ?>