If you take a look at our
"Quick installation" topic, you will see that jqGrid for PHP does not create its own connection to the database, but uses a connection that already exists. This is a very flexible approach in complex applications where the connection to the database had already been created. Typically in our examples we will create the connection using PDO rules, but this is not neccessary and you can reuse your own connection.
PDO Driver
When a PDO driver is used (for MySQL or PostgreSQL) a file named
jqGridPdo.php should be included in addition to the main
jqGrid.php file. The file is available in the
[php] folder of the jqGrid for PHP download package. Please note, that in this case you do not need to specify explicitly which database should be used - MySQL or PostgreSQL. The script will detect this automatically from the connection. Here is an example:
<?php
require_once "php/jqGrid.php";
require_once "php/jqGridPdo.php";
...
?>
Microsoft SQL Driver
When Microsoft SQL Server is used, a file named
jqGridSqlsrv.php should be included in addition to the main
jqGrid.php file. The file is available in the
[php] folder of the jqGrid for PHP download package.
Note: In order to work properly with fields of type "Date", when the connection is created you should also set a property - "ReturnDatesAsStrings"=>true in the connection string. The reason for this is that the driver by default handles dates as PHP date object.
Here is an example:
<?php
$connectionInfo = array("UID" => 'user', "PWD" => 'password',"Database"=>"test", "ReturnDatesAsStrings" => true);
$serverName = "localhost\SQLEXPRESS";
$conn = sqlsrv_connect( $serverName, $connectionInfo);
...
require_once "php/jqGrid.php";
require_once "php/jqGridSqlsrv.php";
...
?>