ขอสอบถามการ connnect server side แบบ sql server 2008
มีใครทำ server side datatable มั่งครับ ผมลอง connect ในไฟล์ ssp.class มันไม่ได้ซะทีครับจนปัญญามากครับ รบกวนด้วยครับ ใน ms sql server 2008 ครับ ถ้าแจกโค้ดจะดีมากครับ แฮะๆ
อันนี้ไม่ใช่ในไฟล์ใน ssp.class นะครับผมลองเอาโค้ดในเน็ตมาปรับเปลี่ยนดู
*------ไฟล์ฝั่ง server side------*
<?php
/*$con=mysqli_connect('localhost','root','','testimg')
or die("connection failed".mysqli_errno());*/
$gaSql['user'] = "";
$gaSql['password'] = "";
$gaSql['db'] = "LIPO\SQLEXPRESS";
$gaSql['server'] = "db_test";
$connectionInfo = array( "Database"=>$gaSql['db'], "UID"=>$gaSql['user'], "PWD"=>$gaSql['password'], "CharacterSet" => "UTF-8");
$con= sqlsrv_connect($gaSql['server'] , $connectionInfo);
if( $con ) {
// echo "Connection success.<br />";
}else{
echo "Connection could not be established.<br />";
die( print_r( sqlsrv_errors(), true));
}
$request=$_REQUEST;
$col =array(
0 => 'ItemSize_Code',
1 => 'ItemSize_Name',
2 => 'ItemSize_Name2',
3 => 'ItemSize_Name3'
); //create column like table in database
$sql ="SELECT COUNT(*) FROM ItemSize";
$query=$con->prepare($sql);
$query->execute();
$totalData=$query->fetchColumn();
$totalFilter=$totalData;
//Search
$sql ="SELECT COUNT(*) FROM ItemSize WHERE 1=1";
if(!empty($request['search']['value'])){
$sql.=" AND (ItemSize_Code Like '".$request['search']['value']."%' ";
$sql.=" OR ItemSize_Name Like '".$request['search']['value']."%' ";
$sql.=" OR ItemSize_Name2 Like '".$request['search']['value']."%' ";
$sql.=" OR ItemSize_Name3 Like '".$request['search']['value']."%' )";
}
$query=$con->prepare($sql);
$query->execute();
$totalData=$query->fetchColumn();
//Order
$sql.=" ORDER BY ".$col[$request['order'][0]['column']]." ".$request['order'][0]['dir']." LIMIT ".
$request['start']." ,".$request['length']." ";
$query=$con->prepare($sql);
$data=array();
while($row=$query->fetch( PDO::FETCH_ASSOC )){
$subdata=array();
$subdata[]=$row[0]; //id
$subdata[]=$row[1]; //name
$subdata[]=$row[2]; //salary
$subdata[]=$row[3]; //age //create event on click in button edit in cell datatable for display modal dialog $row[0] is id in table on database
$subdata[]='<button type="button" id="getEdit" class="btn btn-primary btn-xs" data-toggle="modal" data-target="#myModal" data-id="'.$row[0].'"><i class="glyphicon glyphicon-pencil"> </i>Edit</button>
<button type="button" class="btn btn-danger btn-xs"><i class="glyphicon glyphicon-trash"> </i>Delete</button>';
$data[]=$subdata;
}
$json_data=array(
"draw" => intval($request['draw']),
"recordsTotal" => intval($totalData),
"recordsFiltered" => intval($totalFilter),
"data" => $data
);
echo json_encode($json_data);
?>
Tag : PHP, Ms SQL Server 2008, CSS, HTML5, Ajax
ประวัติการแก้ไข 2018-07-08 09:46:01 2018-07-08 12:21:01 2018-07-08 13:17:25 2018-07-08 17:57:12 2018-07-08 17:58:22
Date :
2018-07-08 05:02:59
By :
champ2514
View :
953
Reply :
1
Load balance : Server 02