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