search
Homephp教程php手册PHP exec mysql return empty

话说,这个问题还是用英文标题比较准确。中文大概意思:PHP EXEC 连接MYSQL 没返回值。 早上客服跟我说,网站的后台无法进行数据库更新了。估计是网站迁移服务器后,某些配置信息更改导致无法运行数据库更新。 检查了一下数据库更新源码。找到关键代码。如下

话说,这个问题还是用英文标题比较准确。中文大概意思:PHP EXEC 连接MYSQL 没返回值。

早上客服跟我说,网站的后台无法进行数据库更新了。估计是网站迁移服务器后,某些配置信息更改导致无法运行数据库更新。

检查了一下数据库更新源码。找到关键代码。如下(类似):

exec('/urs/local/mysql5/bin -u xxx -pxxxx xxxx 
<p>这部分代码是使用PHP exec执行系统的MYSQL命令导入数据库。刚开始以为服务器是数据库密码问题,更改后问题依旧。为了测试是不是这段关键代码无法执行。我写了一个测试代码</p>
<pre class="brush:php;toolbar:false">exec ('/urs/local/mysql5/bin -u xxx -pxxxx xxxx',$a, $code);
echo '<pre class="brush:php;toolbar:false">';
echo var_dump($a);
echo '<br>';
echo var_dump($code);

测试代码运行后,结果竟然是一个空数组?奇怪。正常来说执行无论成不成功,都有结果返回的。于是,在写了一个ls文件代码:

exec ('ls -a',$a, $code);
echo '<pre class="brush:php;toolbar:false">';
echo var_dump($a);
echo '<br>';
echo var_dump($code);

这次却有东西返回了。如图:

return_result

这下子就奇怪了,到底是什么原因出错呢?谷歌一下关键词PHP exec mysql return empty (英语真的很重要的)。有一个国外的提问网站(详细点击这里查看)也有一个类似的问题。对方说,为什么在 一下代码添加上 2>&1 就会有结果返回呢?

exec ('/urs/local/mysql5/bin -u xxx -pxxxx xxxx 2>&1 ',$a, $code);
echo '<pre class="brush:php;toolbar:false">';
echo var_dump($a);
echo '<br>';
echo var_dump($code);

测试了一下,的确如此。继续深入发掘。在CNDS找到一个帖子有讨论过这个问题,不过地址忘记了。如果感兴趣可以去了解一下linux的I/O重定向

如果你也遇到这样的问题,记得在exec 添加上 2>&1 则可以有结果返回了! :)

Statement
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn

Hot AI Tools

Undresser.AI Undress

Undresser.AI Undress

AI-powered app for creating realistic nude photos

AI Clothes Remover

AI Clothes Remover

Online AI tool for removing clothes from photos.

Undress AI Tool

Undress AI Tool

Undress images for free

Clothoff.io

Clothoff.io

AI clothes remover

AI Hentai Generator

AI Hentai Generator

Generate AI Hentai for free.

Hot Article

R.E.P.O. Energy Crystals Explained and What They Do (Yellow Crystal)
4 weeks agoBy尊渡假赌尊渡假赌尊渡假赌
R.E.P.O. Best Graphic Settings
4 weeks agoBy尊渡假赌尊渡假赌尊渡假赌
R.E.P.O. How to Fix Audio if You Can't Hear Anyone
1 months agoBy尊渡假赌尊渡假赌尊渡假赌
R.E.P.O. Chat Commands and How to Use Them
1 months agoBy尊渡假赌尊渡假赌尊渡假赌

Hot Tools

Atom editor mac version download

Atom editor mac version download

The most popular open source editor

MinGW - Minimalist GNU for Windows

MinGW - Minimalist GNU for Windows

This project is in the process of being migrated to osdn.net/projects/mingw, you can continue to follow us there. MinGW: A native Windows port of the GNU Compiler Collection (GCC), freely distributable import libraries and header files for building native Windows applications; includes extensions to the MSVC runtime to support C99 functionality. All MinGW software can run on 64-bit Windows platforms.

EditPlus Chinese cracked version

EditPlus Chinese cracked version

Small size, syntax highlighting, does not support code prompt function

Dreamweaver Mac version

Dreamweaver Mac version

Visual web development tools

Notepad++7.3.1

Notepad++7.3.1

Easy-to-use and free code editor