首页 > 解决方案 > 从 shellscript 检索 cmd 到 php,但使用 pgsql select 或 ssh select

问题描述

您好,我在运行 shell 脚本时尝试检索查询数据,如何打印信息?

以这种方式执行我得到回报。

结果

total 20
-rw-r--r-- 1 root root 876 Aug 22 13:05 Index.html
-rw-r--r-- 1 root root 462 Aug 22 13:05 index2.html
-rw-r--r-- 1 root root  48 Aug 22 13:05 layout.css
-rw-r--r-- 1 root root  69 Aug 22 13:05 promp.php
-rw-r--r-- 1 root root  60 Aug 22 13:05 teste.sh

我的php

<?php
$output = shell_exec('ls -l');
echo "<pre>$output</pre>";
?>

我试过的命令不起作用。

<?php
$output = shell_exec('psql -X -A -d totalipdb -U totalip -h 10.11.12.193 -t -c "select * from trunks where phone_number = '080078795';"');
echo "<pre>$output</pre>";
?>

检索错误

localhost cannot fulfill this request at this time.
HTTP ERROR 500

直接在终端运行我返回了查询结果,但是php显示错误

标签: phpshell

解决方案


推荐阅读