I am trying to create a webservice. Used Blank Application. Code copy paste below. I have deployed this in a local XAMPP on my laptop. When I try to run from a browser I get the data (I am trying to query a table ). But I am not getting the same from POSTMAN
Code :
header(‘Access-Control-Allow-Origin: *’);
header(‘Content-Type: application/json’);
$data_arr = array();
$data_arr[‘data’] = array();
$check_sql = ‘SELECT * from products’;
sc_select(rs, $check_sql);
if (false == {rs})
{
// set response code - 404 Not found
http_response_code(404);
echo json_encode(array(‘message’ => ‘Error while accessing database.’));
}
else
{
while(!$rs->EOF)
{
$id = $rs->fields[0];
$name=$rs->fields[1];
$description=$rs->fields[2];
$price=$rs->fields[3];
$category_id=$rs->fields[4];
$category_name = $rs->fields[5];
$post_item = array(
“id” => $id,
“name” => $name,
“description” => html_entity_decode($description),
“price” => $price,
“category_id” => $category_id,
“category_name” => $category_name
);
array_push ($data_arr[‘data’], $post_item);
$rs->MoveNext();
}
$rs->Close();
// set response code - 200 OK
http_response_code(200);
echo json_encode($data_arr);
}
In the Microsoft Edge Browser (NOTE Chrome takes almost a minute for the fist instance) http://localhost:9090/scapi/readproducts/readproducts.php
following data is returned
[LEFT]{“data”:[{“id”:“1”,“name”:“LG P880 4X HD”,“description”:“My first awesome phone!”,“price”:“336”,“category_id”:“3”,“category_ name”:“2014-06-01 01:12:26”},{“id”:“2”,“name”:“Google Nexus 4”,“description”:“The most awesome phone of 2013!”,“price”:“299”,“category_id”:“2”,“category_n ame”:“2014-06-01 01:12:26”},{“id”:“3”,“name”:“Samsung Galaxy S4”,“description”:“How about no?”,“price”:“600”,“category_id”:“3”,“category_nam e”:“2014-06-01 01:12:26”},{“id”:“6”,“name”:“Bench Shirt”,“description”:“The best shirt!”,“price”:“29”,“category_id”:“1”,“category_n ame”:“2014-06-01 01:12:26”},{“id”:“7”,“name”:“Lenovo Laptop”,“description”:“My business partner.”,“price”:“399”,“category_id”:“2”,“categor y_name”:“2014-06-01 01:13:45”},{“id”:“8”,“name”:“Samsung Galaxy Tab 10.1”,“description”:“Good tablet.”,“price”:“259”,“category_id”:“2”,“category name":“2014-06-01 01:14:13”},{“id”:“9”,“name”:“Spalding Watch”,“description”:“My sports watch.”,“price”:“199”,“category_id”:“1”,"category name”:“2014-06-01 01:18:36”},{“id”:“10”,“name”:“Sony Smart Watch”,“description”:“The coolest smart watch!”,“price”:“300”,“category_id”:“2”,“category_ name”:“2014-06-06 17:10:01”},{“id”:“11”,“name”:“Huawei Y300”,“description”:“For testing purposes.”,“price”:“100”,“category_id”:“2”,“catego ry_name”:“2014-06-06 17:11:04”},{“id”:“12”,“name”:“Abercrombie Lake Arnold Shirt”,“description”:“Perfect as gift!”,“price”:“60”,“category_id”:“1”,“category_na me”:“2014-06-06 17:12:21”},{“id”:“13”,“name”:“Abercrombie Allen Brook Shirt”,“description”:“Cool red shirt!”,“price”:“70”,“category_id”:“1”,“category_n ame”:“2014-06-06 17:12:59”},{“id”:“26”,“name”:“Another product”,“description”:“Awesome product!”,“price”:“555”,“category_id”:“2”,“categor y_name”:“2014-11-22 19:07:34”},{“id”:“28”,“name”:“Wallet”,"description ":“You can absolutely use this one!”,“price”:“799”,“category_id”:“6”,“category_na me”:“2014-12-04 21:12:03”},{“id”:“31”,“name”:“Amanda Waller Shirt”,“description”:“New awesome shirt!”,“price”:“333”,“category_id”:“1”,“category_ name”:“2014-12-13 00:52:54”},{“id”:“42”,“name”:“Nike Shoes for Men”,“description”:“Nike Shoes”,“price”:“12999”,“category_id”:“3”,“category name":“2015-12-12 06:47:08”},{“id”:“48”,“name”:“Bristol Shoes”,“description”:“Awesome shoes.”,“price”:“999”,“category_id”:“5”,"category name”:“2016-01-08 06:36:37”},{“id”:“60”,“name”:“Rolex Watch”,“description”:“Luxury watch.”,“price”:“25000”,“category_id”:“1”,“categor y_name”:“2016-01-11 15:46:02”}]}
IN POSTMAN WITH SAME ADDRESS[/LEFT]
<style type=“text/css”>.scButton_default { font-family: Tahoma, Arial, sans-serif;box-sizing: border-box;; font-size: 13px; color: #3C4858; font-weight: normal; background-color: #FFFFFF; border-style: solid; border-width: 1px; padding: 0 12px !important; }.scButton_disabled { font-family: Tahoma, Arial, sans-serif;box-sizing: border-box;; font-size: 13px; color: #7d7d7d; font-weight: normal; background-color: #FFFFFF; border-style: solid; border-width: 1px; padding: 0 12px; }.scButton_group { font-family: Tahoma, Arial, sans-serif;box-sizing: border-box;; font-size: 13px; color: #3C4858; font-weight: normal; background-color: #FFFFFF; border-style: solid; border-width: 1px; padding: 7.8px 15px;margin:0px -5px !important; }.scButton_groupdisabled { font-family: Tahoma, Arial, sans-serif;box-sizing: border-box;; font-size: 13px; color: #7d7d7d; font-weight: normal; background-color: #FFFFFF; border-style: solid; border-width: 1px; padding: 7.8px 15px;margin:0px -5px !important; }.scButton_groupfirst { font-family: Tahoma, Arial, sans-serif;box-sizing: border-box;; font-size: 13px; color: #3C4858; font-weight: normal; background-color: #FFFFFF; border-style: solid; border-width: 1px; padding: 7.8px 15px; }.scButton_grouplast { font-family: Tahoma, Arial, sans-serif;box-sizing: border-box;; font-size: 13px; color: #3C4858; font-weight: normal; background-color: #FFFFFF; border-style: solid; border-width: 1px; padding: 0 12px; }.scButton_onmousedown { font-family: Tahoma, Arial, sans-serif;box-sizing: border-box;box-shadow: inset 0 1px 0 rgba(31, 45, 61, 0.15);; font-size: 13px; color: #FFFFFF; font-weight: normal; background-color: #1B8FC8;}.scButton_default:active img{filter: brightness(2)}.scButton_default:active{; border-style: solid; border-width: 1px; padding: 8px 10px; }.scButton_onmouseover { font-family: Tahoma, Arial, sans-serif;box-sizing: border-box;box-shadow: inset 0 -1px 0 rgba(31, 45, 61, 0.15);; font-size: 13px; color: #FFFFFF; font-weight: normal; background-color: #1B8FC8;}.scButton_default:hover img, .scButton_groupfirst:hover img, .scButton_group:hover img{filter: brightness(2);}.scButton_default:hover{; border-style: solid; border-width: 1px; padding: 8px 10px; }.scButton_small { font-family: Tahoma, Arial, sans-serif;box-sizing: border-box;; font-size: 13px; color: #3C4858; font-weight: normal; background-color: #FFFFFF; border-style: solid; border-width: 1px; padding: 3px 13px !important; }.scLink_default { text-decoration: underline; font-size: 13px; color: #1a0dab; }.scLink_default:visited { text-decoration: underline; font-size: 13px; color: #660099; }.scLink_default:active { text-decoration: underline; font-size: 13px; color: #1a0dab; }.scLink_default:hover { text-decoration: underline; font-size: 13px; color: #1a0dab; }</style>
<table width=“80%” border=“1” height=“117”>
<tr>
<td bgcolor="">
<b>
<font size=“4”>The database connection was not found, contact the system administrator. Connection:</font> conn_mysql
</b>
</td>
</tr>
</table>
<input type=“button” id=“sai” onClick=“window.location=’’; return false” class=“scButton_default” value="" title="" style=“vertical-align: middle;”>
Can you please help what could be the problem.
Thanks in advance