dsy19811981 2016-12-30 23:02
浏览 285

使用终端连接到Mariadb

I use PHP to send a query to the terminal and I want to receive the table that the database produces. I am new to PHP and having difficulties with the connection of the website and the database that I access from the terminal.

    <?php

    $con = new mysqli('localhost','root','','db');
    $query = "";

    if($con->connect_error) {
        die("Connection failed: " . $conn->connect_error);
    } else {
        echo "Connection Successful."
    }

    if($_SERVER["REQUEST_METHOD"] == ["POST"]) {
        $query = test_input($_POST["uni_name"]);
    }

    $prompt = 'select * from students where university like ' . $query . '%';


    $dir = shell_exec("use db");
    if($dir == NULL) {
        $output = shell_exec($prompt);
        echo "test";
    }

    setModal($output);

    function test_input($data) {
        $data = trim($data);
        $data = stripslashes($data);
        $data = htmlspecialchars($data);
        return $data;
    }

    function setModal($query) {
        echo '<div class="modal fade" id="myModal" tabindex="-1" role="dialog" aria-labelledby="myModalLabel" aria-hidden="true">
    <div class="modal-dialog" role="document">
    <div class="modal-content">
      <div class="modal-header">
        <button type="button" class="close" data-dismiss="modal" aria-label="Close">
          <span aria-hidden="true">&times;</span>
        </button>
        <h4 class="modal-title" id="myModalLabel">Graduate Information</h4>
      </div>
      <div class="modal-body">
      '; 
        echo $query;
        echo '
      </div>
      <div class="modal-footer">
        <button type="button" class="btn btn-secondary" data-dismiss="modal">Close</button>
      </div>
    </div>
  </div>
</div>';
    }
?>

The setModal function is to create a Bootstrap modal and display the info I get from the database. My main problem is the connection between the database and the website.

Thanks in advance..

  • 写回答

0条回答 默认 最新

    报告相同问题?

    悬赏问题

    • ¥20 ML307A在使用AT命令连接EMQX平台的MQTT时被拒绝
    • ¥20 腾讯企业邮箱邮件可以恢复么
    • ¥15 有人知道怎么将自己的迁移策略布到edgecloudsim上使用吗?
    • ¥15 错误 LNK2001 无法解析的外部符号
    • ¥50 安装pyaudiokits失败
    • ¥15 计组这些题应该咋做呀
    • ¥60 更换迈创SOL6M4AE卡的时候,驱动要重新装才能使用,怎么解决?
    • ¥15 让node服务器有自动加载文件的功能
    • ¥15 jmeter脚本回放有的是对的有的是错的
    • ¥15 r语言蛋白组学相关问题