0

I am working on a small project which could use some sort of datagrid table with CRUD and some sorting. I found this solution: Add, Edit and Delete Record using Bootgrid, PHP and MySQL. My main problem is that mysqli driver, my project run on MSSQL so I need to use PDO. Is it possible to use PDO in that solution (I think it should be doable but wanna be sure)? If so, can somebody help me with connection object? I will try do the rest on my own.

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;
    }
}
?>

Ok i read up about pdo, can somebody revise my connection string.

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;
            }
}
Zdenek S.
  • 57
  • 6
  • [Microsoft SQL Server and Sybase Functions (PDO_DBLIB)](http://php.net/manual/en/ref.pdo-dblib.php) – Mohammad Oct 19 '17 at 06:47
  • Go to [PHP: PDO Drivers](http://php.net/manual/en/pdo.drivers.php) and choose one of the two **MS SQL Server (PDO)** entries (PDO_DBLIB or PDO_SQLSRV), depending on your system. Then just follow the instructions. –  Oct 19 '17 at 07:16
  • And for the rest of PDO usage just read this great tutorial: [(The only proper) PDO tutorial](https://phpdelusions.net/pdo). –  Oct 19 '17 at 07:19

0 Answers0