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条回答 默认 最新

    报告相同问题?

    悬赏问题

    • ¥15 请教一下各位,为什么我这个没有实现模拟点击
    • ¥15 执行 virtuoso 命令后,界面没有,cadence 启动不起来
    • ¥50 comfyui下连接animatediff节点生成视频质量非常差的原因
    • ¥20 有关区间dp的问题求解
    • ¥15 多电路系统共用电源的串扰问题
    • ¥15 slam rangenet++配置
    • ¥15 有没有研究水声通信方面的帮我改俩matlab代码
    • ¥15 ubuntu子系统密码忘记
    • ¥15 保护模式-系统加载-段寄存器
    • ¥15 电脑桌面设定一个区域禁止鼠标操作