Use Sql server With php
To connect Ms SQL Server In PhP
Note: This is working in the Go-daddy windows server No setting Required if use in the local they are some setting required in Php.ini and add mssql.dll in xamp or wamp server.
Connect.Php
<?php
$server = Server Name/IP;
$options = array( "UID" => "Username", "PWD" => "Password", "Database" => "DbName");
$conn = sqlsrv_connect($server, $options);
?>
Note: Can't Close The Connection At Last.
To Execute the Store Procedure In Php Web services
Web_services.php
<?php
include("connect.php"); // Connection File Include Here
header('Content-Type:application/json;charset=utf8');
header('Access-Control-Allow-Origin: *');
header('Access-Control-Allow-Methods:GET,PUT,POST,DELETE,OPTIONS');
header('Access-Control-Allow-Headers:Accept,Origin,Content-Type,X-Requested-With');
header('Access-Control-Allow-Credentials:true');
// Above All Header include For the Result Convert in json other wise header error when call webservices
function searchGia($Shape,$color,$purity,$polish,$cut,$pricemax,$pricemin,$caratMax,$caratmin,$symm,$fls,$userid)
{
include "connect.php";
$sql = "exec gia_Search '$Shape','$color','$purity','$polish','$cut','$pricemax','$pricemin','$caratMax','$caratmin','$symm','$fls','$userid'";
// Store Procedure take as Query In $sql
$result = sqlsrv_query($conn,$sql);
//Call store procedure in Sql_query function
$item = array();
while( $row = sqlsrv_fetch_array($result,SQLSRV_FETCH_ASSOC) )
{
//Fetch Record as Array from the $result
$item[] = array(
'SEQ_NO' => $row ["SEQ_NO"],
'PACKET_NO' => $row ["PACKET_NO"],
'REPORT_NO' => $row ["REPORT_NO"],
'SHAPE_SEQ' => $row ["SHAPE_SEQ"],
'CTS' => $row ["CTS"],
'RANGE_SEQ' => $row ["RANGE_SEQ"],
'COLOR_SEQ' => $row ["COLOR_SEQ"],
'PURITY_SEQ' => $row ["PURITY_SEQ"],
'CUT_SEQ' => $row ["CUT_SEQ"],
'POLISH_SEQ' => $row ["POLISH_SEQ"],
'SYMM_SEQ' => $row ["SYMM_SEQ"],
'PROP_SEQ' => $row ["PROP_SEQ"],
'FLS_SEQ' => $row ["FLS_SEQ"],
'LAB_SEQ' => $row ["LAB_SEQ"],
'LENGTH_1' => $row ["LENGTH_1"],
'WIDTH' => $row ["WIDTH"],
'DEPTH' => $row ["DEPTH"],
'TABLE_PER' => $row ["TABLE_PER"],
'DEPTH_PER' => $row ["DEPTH_PER"],
'CROWN_ANGLE' => $row ["CROWN_ANGLE"],
'CROWN_HEIGHT' => $row ["CROWN_HEIGHT"],
'PAVILLION_ANGLE' => $row ["PAVILLION_ANGLE"],
'PAVILLION_HEIGHT' => $row ["PAVILLION_HEIGHT"],
'CENTER_NATTS' => $row ["CENTER_NATTS"],
'SIDE_NATTS' => $row ["SIDE_NATTS"],
'CENTER_FEATHER' => $row ["CENTER_FEATHER"],
'SIDE_FEATHER' => $row ["SIDE_FEATHER"],
'TABLE_OPEN' => $row ["TABLE_OPEN"],
'PAVILLION_OPEN' => $row ["PAVILLION_OPEN"],
'CROWN_OPEN' => $row ["CROWN_OPEN"],
'RATE' => $row ["RATE"],
'DISC_PER' => $row ["DISC_PER"],
'HA' => $row ["HA"]
);
}
if(count($item) > 0)
{
return json_encode(array('success' => 1 ,'data'=>$item));
//Return Data As the Json format
}
else
{
return array('success' => 0 );
}
}
?>
Note: IN Ms Sql Server here use the sqlsrv_connect to connect the Database
and query Execute use the sqlsrv_query and At last Fetch Data sqlsrv_fetch_array($result,SQLSRV_FETCH_ASSOC)
Comments
Post a Comment