带有PDO数据库驱动程序的Bootgrid

时间:2017-10-19 06:39:30

标签: php mysql sql-server mysqli pdo

我正在开发一个小项目,它可以使用某种带有CRUD的数据网格表和一些排序。我找到了这个解决方案:Add, Edit and Delete Record using Bootgrid, PHP and MySQL。我的主要问题是mysqli驱动程序,我的项目运行在MSSQL上,所以我需要使用PDO。是否有可能在该解决方案中使用PDO(我认为它应该可行但是要确定)?如果是这样,有人可以帮我连接对象吗?我将尝试自己做其余的事情。

Class dbObj {
    var $servername = "localhost";
    var $username = "root";
    var $password = "";
    var $dbname = "test";
    var $conn;

    function getConnstring() {
        $con = mysqli_connect($this->servername, $this->username, $this->password, $this->dbname)
            or die("Connection failed: " . mysqli_connect_error());

        /* check connection */
        if (mysqli_connect_errno()) {
            printf("Connect failed: %s\n", mysqli_connect_error());
            exit();
        } else {
            $this->conn = $con;
        }

        return $this->conn;
    }
}
?>

好的,我读了一下pdo,有人可以修改我的连接字符串。

Class dbObj{
    /* Database connection start */
    var $servername = "localhost";
    var $username = "root";
    var $password = "";
    var $dbname = "test";
    var $conn;
    function getConnstring() {
            $con = new PDO("mysql:host={$this->servername};dbname={$this->dbname};",$this->username,$this->password);
            $con->setAttribute(PDO::ATTR_ERRMODE, PDO::ERRMODE_EXCEPTION);
            $this->conn = $con;
            return $this->conn;
            }
}

0 个答案:

没有答案