mysql execute直接执行_如何在PHP中执行mysql脚本文件?(How to execute mysql script file in PHP?)...

如何在PHP中执行mysql脚本文件?(How to execute mysql script file in PHP?)

我有几乎100MB的example.sql文件。 (实际上来自另一个数据库的数据导出文件)

我想让用户能够通过我的应用程序中的某个界面运行此文件。 你能指导我怎么做? 我应该把它当作简单的文本文件吗? 要么有任何快捷方式???

换句话说,我想在phpMyAdmin中添加与导入功能相同的功能。

如果你能在PHPclass.org上推荐一些很棒的课程。

I have almost 100MB of example.sql file. (Actually data export file from another database)

I want to give user the ability to run this file through some interface in my application. Can you please guide me how can i do that? Should i treat it as simple text file? Either there is any quick way???

In other words, I want to add same functionality as we have in phpMyAdmin, The import functionality.

If you can refer me some class on PHPclass.org that will be great.

原文:https://stackoverflow.com/questions/7840044

更新时间:2020-02-14 11:07

最满意答案

function import_file($filename){

if ($file = file_get_contents($filename)){

foreach(explode(";", $file) as $query){

$query = trim($query);

if (!empty($query) && $query != ";") {

mysql_query($query);

}

}

}

}

可以调用

import_file("files/files.sql");

但是,如果文件包含分号,则此功能将无法正常工作; 在其他地方而不是在查询结束时

function import_file($filename){

if ($file = file_get_contents($filename)){

foreach(explode(";", $file) as $query){

$query = trim($query);

if (!empty($query) && $query != ";") {

mysql_query($query);

}

}

}

}

can be called with

import_file("files/files.sql");

However, this function will not work properly if file includes semicolon ; somewhere else than at the end of the query

2011-10-20

相关问答

您可以从命令行手动调用PHP脚本 hello.php

echo 'hello world!';

?>

Command line:

php hello.php

Output:

hello world!

请参阅文档: http : //php.net/manual/en/features.commandline.php 编辑 OP编辑的问题添加一个关键的细节:该脚本将由另一个脚本执行。 有几种方法。 首先也是最简单的,你可以简单地包含文件。 当你包含一个文件时,其中的代码是“执行”

...

您的应用程序可能有多种方式受到攻击,例如SQL注入,嗅探的FTP密码或代码本身中的漏洞。 保持这些内容尽可能地本地化以防止一个区域中的漏洞进行级联通常是个好主意。 例如,假设您在数据库中存储敏感数据。 通常,您将使用未存储在数据库本身中的salt和密钥以某种方式加密此数据。 然后,如果您的数据库被SQL注入攻击,攻击者可能会造成损害,但他们将无法窃取敏感信息。 但是,如果您在数据库中执行以文本形式存储的PHP,攻击者肯定会意识到并更新它以执行他的代码,从而可以弄清楚如何加密敏感数据并解密它。 简而

...

你可以在Viana-BackupMailer中分享代码吗? 可能有两个原因导致它无法执行(包括权限): 访问权限 - 你/ cron所有者无权执行这个php文件 执行此php文件的用户无权访问文件夹/ Viana-BackupMailer /或在那里创建文件/或运行mysqldump命令 Can you share the code in Viana-BackupMailer? There are probably two reasons why it couldn't be executed (

...

看来你的jar需要一台X服务器才能运行。 无法使用':0.0'作为DISPLAY变量的值连接到X11窗口服务器。 当您从命令行运行它时,您是否正在运行X? 如果你这样做,这将解释为什么它在那里工作,而不是PHP。 您可以尝试从PHP“劫持”正在运行的X会话。 exec('DISPLAY=:0 java -jar simulations/simulation.jar');

您可能必须首先从命令行运行xhost +localhost (或xhost + ),以允许用户运行PHP以连接到X. It s

...

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值