Skip to content

Instantly share code, notes, and snippets.

@gridphp
Created March 26, 2021 16:19
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save gridphp/ead1eec3d2d703ebc30a3321ab08b37c to your computer and use it in GitHub Desktop.
Save gridphp/ead1eec3d2d703ebc30a3321ab08b37c to your computer and use it in GitHub Desktop.
PDO SQL server connection sample
<?php
/**
* PHP Grid Component
*
* @author Abu Ghufran <gridphp@gmail.com> - http://www.phpgrid.org
* @version 1.5.2
* @license: see license.txt included in package
*/
// $db_conf = array();
// $db_conf["type"] = "mssqlnative"; // or mssql
// $db_conf["server"] = "den1.mssql5.gear.host"; // ip:port
// $db_conf["user"] = 'testdb63';
// $db_conf["password"] = 'Oh6K_uw?bbnL';
// $db_conf["database"] = "testdb63";
$db_conf = array();
$db_conf["type"] = "pdo";
$db_conf["server"] = "sqlsrv:Server=den1.mssql5.gear.host";
$db_conf["user"] = "testdb63"; // username
$db_conf["password"] = "Oh6K_uw?bbnL"; // password
$db_conf["database"] = "testdb63"; // database
// $db_conf = array();
// $db_conf["type"] = "odbc_mssql";
// $db_conf["server"] = "Driver={SQL Server};Server=den1.mssql5.gear.host;Database=testdb63;";
// $db_conf["user"] = "testdb63";
// $db_conf["password"] = "Oh6K_uw?bbnL";
// $db_conf["database"] = null;
// include and create object
$base_path = "../../lib/";
include($base_path."inc/jqgrid_dist.php");
$g = new jqgrid($db_conf);
$g->table = "Orders"; // Don't need table if we have a select command!!
$g->select_command = "SELECT * FROM Orders";
// $grid["view_options"] = array("width"=>"500");
// $grid["grouping"] = true; //
// $grid["groupingView"] = array();
// $grid["groupingView"]["groupField"] = array("id"); // specify column name to group listing
// $grid["groupingView"]["groupColumnShow"] = array(false); // either show grouped column in list or not (default: true)
// $grid["groupingView"]["groupText"] = array("<b>Project: {0} - {1} Entries</b>"); // {0} is grouped value, {1} is count in group
// $grid["groupingView"]["groupOrder"] = array("asc"); // show group in asc or desc order
// $grid["groupingView"]["groupDataSorted"] = array(true); // show sorted data within group
// $grid["groupingView"]["groupSummary"] = array(true); // work with summaryType, summaryTpl, see column: $col2["name"] = "total";
// $grid["groupingView"]["groupCollapse"] = false; // Turn true to show group collapse (default: false)
// $grid["groupingView"]["showSummaryOnHide"] = true;
// $g->set_options($grid);
// $g->set_columns($cols,true);
$out = $g->render("list1");
?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.1//EN" "http://www.w3.org/TR/xhtml11/DTD/xhtml11.dtd">
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<link rel="stylesheet" type="text/css" media="screen" href="../../lib/js/themes/redmond/jquery-ui.custom.css"></link>
<link rel="stylesheet" type="text/css" media="screen" href="../../lib/js/jqgrid/css/ui.jqgrid.css"></link>
<script src="../../lib/js/jquery.min.js" type="text/javascript"></script>
<script src="../../lib/js/jqgrid/js/i18n/grid.locale-en.js" type="text/javascript"></script>
<script src="../../lib/js/jqgrid/js/jquery.jqGrid.min.js" type="text/javascript"></script>
<script src="../../lib/js/themes/jquery-ui.custom.min.js" type="text/javascript"></script>
</head>
<body>
<div style="margin:10px">
<?php echo $out?>
</div>
</body>
</html>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment