I am trying to get a JSON from a MySQL database, but it does not recover anything. Here my code:
db_config.php
<?php
/*
* All database connection variables
*/
define('DB_USER', "root"); // db user
define('DB_PASSWORD', ""); // db password (mention your db password here)
define('DB_DATABASE', "biblioapp"); // database name
define('DB_SERVER', "localhost"); // db server
?>
db_connect
<?php
/**
* A class file to connect to database
*/
class DB_CONNECT{
// constructor
function __construct() {
// connecting to database
$this->connect();
}
// destructor
function __destruct() {
// closing db connection
$this->close();
}
/**
* Function to connect with database
*/
function connect() {
// import database connection variables
require_once __DIR__ . '/db_config.php';
// Connecting to mysql database
$con = mysql_connect(DB_SERVER, DB_USER, DB_PASSWORD) or die(mysql_error());
// Selecing database
$db = mysql_select_db(DB_DATABASE) or die(mysql_error()) or die(mysql_error());
// returing connection cursor
return $con;
}
/**
* Function to close db connection
*/
function close() {
// closing db connection
mysql_close();
}
}
?>
get_products_details.php
<?php
$response = array();
// include db connect class
require_once __DIR__ . '/db_connect.php';
// connecting to db
$db = new DB_CONNECT();
// check for post data
$search = '';
if (isset($_POST['search'])){
$search = strtolower($_POST['search']);
// get a product from products table
$result = mysql_query("SELECT * FROM registres WHERE titol LIKE '%".$search."%' OR autor LIKE '%".$search."%'");
if (!empty($result)) {
// check for empty result
if (mysql_num_rows($result) > 0) {
$result = mysql_fetch_array($result);
$product = array();
$product["id"] = $result["id"];
$product["titol"] = $result["titol"];
$product["autor"] = $result["autor"];
$product["descripcion"] = $result["descripcion"];
// success
$response["success"] = 1;
// user node
$response["product"] = array();
array_push($response["product"], $product);
// echoing JSON response
echo json_encode($response);
} else {
// no product found
$response["success"] = 0;
$response["message"] = "No product found";
// echo no users JSON
echo json_encode($response);
}
} else {
// no product found
$response["success"] = 0;
$response["message"] = "No product found";
// echo no users JSON
echo json_encode($response);
}
} else {
// required field is missing
$response["success"] = 0;
$response["message"] = "Required field(s) is missing";
// echoing JSON response
echo json_encode($response);
}
?>
get_all_products.php
<?php
// array for JSON response
$response = array();
// include db connect class
require_once __DIR__ . '/db_connect.php';
// connecting to db
$db = new DB_CONNECT();
// get all products from products table
$result = mysql_query("SELECT *FROM registres") or die(mysql_error());
// check for empty result
if (mysql_num_rows($result) > 0) {
// looping through all results
// products node
$response["registres"] = array();
while ($row = mysql_fetch_array($result)) {
// temp user array
$product = array();
$product["id"] = $result["id"];
$product["titol"] = $result["titol"];
$product["autor"] = $result["autor"];
$product["descripcion"] = $result["descripcion"];
// push single product into final response array
array_push($response["registres"], $product);
}
// success
$response["success"] = 1;
// echoing JSON response
echo json_encode($response);
} else {
// no products found
$response["success"] = 0;
$response["message"] = "No products found";
// echo no users JSON
echo json_encode($response);
}
?>
If I go to localhost/json/get_product_details.php I receive this:
{"success":0,"message":"Required field(s) is missing"}
If i go to localhost/json/get_all_products.php I receive this:
{"registres":[{"id":null,"titol":null,"autor":null,"descripcion":null},{"id":null,"titol":null,"autor":null,"descripcion":null},{"id":null,"titol":null,"autor":null,"descripcion":null},{"id":null,"titol":null,"autor":null,"descripcion":null},{"id":null,"titol":null,"autor":null,"descripcion":null}],"success":1}
What's wrong here? Thanks...
while ($row = mysql_fetch_array($result)) {
$product = array();
$product["id"] = $result["id"];
Your results are not in $result, but in $row :
$product["id"] = $row["id"];
I see nothing common with json in your issue :-)
The only problem you have - empty values in array you've created.
You didn't give us any information about table structure you have, and values you are trying to debug.
So just a quick fix to start better debugging could be:
while ($row = mysql_fetch_array($result, MYSQL_ASSOC)) {
$response["registres"][] = $row;
}
but reviewing your code I want to suggest you to stop using deprecated mysql_ calls. Use mysqli or PDO.
Related
I am newbie to PHP webservices using MySQL. I follow this tutorial. I created one table -> loan_applications using phpmyadmin. Currenlty I have 3 records in table related to id 1. I would like to retrive all 3 records and would like to encode it in json.
I tried multiple way and tried googling but unable to get proper json array in response. Here is my get_applications_list.php
<?php
require_once 'include/DB_Functions.php';
$db = new DB_Functions();
// json response array
$response = array();
if (isset($_GET['id'])) {
// receiving the post params
$id = $_GET['id'];
$applications = $db -> getApplicationsList($id);
if ($applications) {
// got applications successfully
$response["status"] = 0;
$response["id"] = $applications["id"];
$response["application_id"] = $applications["application_id"];
$response["requested_amount"] = $applications["requested_amount"];
$response["interest_per_day"] = $applications["interest_per_day"];
$response["gst"] = $applications["gst"];
$response["tenure"] = $applications["tenure"];
$response["processing_fees"] = $applications["processing_fees"];
$response["amount_user_get"] = $applications["amount_user_get"];
$response["amount_user_pay"] = $applications["amount_user_pay"];
$response["application_latitude"] = $applications["application_latitude"];
$response["application_longitude"] = $applications["application_longitude"];
$response["application_status"] = $applications["application_status"];
$response["created_at"] = $applications["created_at"];
$response["updated_at"] = $applications["updated_at"];
$response["message"] = "Applications details fetched successfully";
echo json_encode($response);
} else {
// applications failed to store
$response["status"] = 1;
$response["message"] = "Unknown error occurred in getting details!";
echo json_encode($response);
}
} else {
// receiving the post params
$response["status"] = 2;
$response["message"] = "Required parameters is missing!";
echo json_encode($response);
}
?>
Here is my DB_Functions.php
<?php
class DB_Functions {
private $conn;
// constructor
function __construct() {
require_once 'DB_Connect.php';
// connecting to database
$db = new Db_Connect();
$this->conn = $db->connect();
}
// destructor
function __destruct() {
}
public function getApplicationsList($id){
$stmt = $this->conn->prepare("SELECT * FROM loan_applications WHERE id = ?");
$stmt->bind_param("s", $id);
$stmt->execute();
$applications = $stmt->get_result()->fetch_assoc();
$stmt->close();
if($applications){
return $applications;
}else {
return false;
}
}
}
?>
Here is response which I am getting :
{"status":0,"id":1,"application_id":1,"requested_amount":5000,"interest_per_day":"0.50","gst":18,"tenure":28,"processing_fees":"5.00","amount_user_get":4705,"amount_user_pay":5700,"application_latitude":"9.999999999","application_longitude":"9.999999999","application_status":1,"created_at":"2018-10-10 21:45:17","updated_at":"0000-00-00 00:00:00","message":"Applications details fetched successfully"}
I am getting only one record but i need all 3 record which associated with id 1. I tried lot but unable to get.
So multiple problems here
1 - Although unsure but Currenlty I have 3 records in table related to id 1 seems incorrect statement. If id is primary key, you cannot have 3 records against one id
2 - $stmt->get_result()->fetch_assoc(); will always return one row, to get multiple rows or collection of rows you will need to do it like following
if ($result = $mysqli->query($query)) {
/* fetch associative array */
while ($row = $result->fetch_assoc()) {
printf ("%s (%s)\n", $row["Name"], $row["CountryCode"]);
}
/* free result set */
$result->free();
}
3 - Its quite clear from following code that you are actually sending only one row back
if ($applications) {
// got applications successfully
$response["status"] = 0;
$response["id"] = $applications["id"];
$response["application_id"] = $applications["application_id"];
$response["requested_amount"] = $applications["requested_amount"];
$response["interest_per_day"] = $applications["interest_per_day"];
$response["gst"] = $applications["gst"];
$response["tenure"] = $applications["tenure"];
$response["processing_fees"] = $applications["processing_fees"];
$response["amount_user_get"] = $applications["amount_user_get"];
$response["amount_user_pay"] = $applications["amount_user_pay"];
$response["application_latitude"] = $applications["application_latitude"];
$response["application_longitude"] = $applications["application_longitude"];
$response["application_status"] = $applications["application_status"];
$response["created_at"] = $applications["created_at"];
$response["updated_at"] = $applications["updated_at"];
$response["message"] = "Applications details fetched successfully";
echo json_encode($response);
}
You should do it like this
$applications = getAllApplications(); //returns array of applications
$response['applications'] = $applications; // if they keys you want to send and database fields are same you don't need to set them separately
return json_encode($response);
I'm connecting to a MySQL database with PHP, and in the beginning I used the mysql_ methods. I then found out that these methods are deprecated, so I've switched to PDO, and am now in the midst of changing my code (and I don't have any experience with PHP PDO). Now I'm getting an error and I (and also my colleague) cannot figure out why I get it, and the code is very straightforward, so I'm not sure..
I have a script that configures connection variables like this:
<?php
define('DB_USER', "user"); // db user
define('DB_PASSWORD', "password"); // db password
define('DB_DATABASE', "myDB"); // database name
define('DB_SERVER', "localhost"); // db server
?>
Then I've defined a class for connecting to the database:
<?php
/**
* A class file to connect to database
*/
class DB_CONNECT {
private $con;
// constructor
function __construct() {
// connecting to database
$this->connect();
}
// destructor
function __destruct() {
// closing db connection
$this->con = null;
}
/**
* Function to connect with database
*/
function connect() {
try {
// import database connection variables
require_once __DIR__ . '/db_config.php';
$this->con = new PDO("mysql:host=".DB_SERVER.";dbname=".DB_DATABASE.";charset=utf8mb4", DB_USER, DB_PASSWORD);
$this->con -> setAttribute(PDO::ATTR_ERRMODE, PDO::ERRMODE_EXCEPTION);
return $con;
} catch (PDOException $ex) {
die("Error connecting to DB: ".$ex->getMessage());
}
}
}
?>
Now I'm running this next script, which fetches all items from one table in my database:
<?php
// array for JSON response
$response = array();
// include db connect class
require_once __DIR__ . '/db_connect.php';
// connecting to db
$db = new DB_CONNECT();
// get all products from products table
//$result = mysql_query("SELECT * FROM ITEM") or die(mysql_error());
$query = "SELECT * FROM ITEM";
$stmt = $db->prepare($query); //eror here!
$stmt -> execute();
//foreach($db->query("SELECT * FROM ITEM") as $row) {
// $response["products"] = array();
//}
// check for empty result
if ($stmt->fetchColumn() > 0 ) {
// looping through all results
// products node
$response["products"] = array();
while ($row =$stmt->fetch(PDO::FETCH_ASSOC)) {
// temp user array
$product = array();
$product["name"] = $row["name"];
$product["am"] = $row["am"];
// push single product into final response array
array_push($response["products"], $product);
}
// success
$response["success"] = 1;
// echoing JSON response
echo json_encode($response);
} else {
// no products found
$response["success"] = 0;
$response["message"] = "No products found";
// echo no users JSON
echo json_encode($response);
}
?>
It's this:
$this->$con = new PDO(etc...
^---
$con is undefined in this context, which means you're doing the equivalent of $this->null = new PDO ....
Try $this->con instead. Note the lack of $ on con.
this is my php file
<?php
/*
* Following code will create a new product row
* All product details are read from HTTP Post Request
*/
// array for JSON response
$response = array();
// check for required fields
if (isset($_POST['userName']) && isset($_POST['userContact']) && isset($_POST['userAddress']) && isset($_POST['userStore']) && isset($_POST['userRequest'])) {
$userName = $_POST['userName'];
$userContact = $_POST['userContact'];
$userAddress = $_POST['userAddress'];
$userStore = $_POST['userStore'];
$userRequest = $_POST['userRequest'];
// include db connect class
require_once __DIR__ . '/db_connect.php';
// connecting to db
$db = new DB_CONNECT();
// mysql inserting a new row
$result = "INSERT INTO userrequests(userName, contactNumber, userAddress, storeList, requestBody) VALUES('$userName', '$userContact', '$userAddress', '$userStore', '$userRequest')";
// check if row inserted or not
if (mysqli_query($result,$db)) {
// successfully inserted into database
$response["success"] = 1;
$response["message"] = "Product successfully created.";
// echoing JSON response
echo json_encode($response);
echo $result;
} else {
// failed to insert row
$response["success"] = 0;
$response["message"] = "IsitdispllayingthusOops! An error occurred.";
// echoing JSON response
echo json_encode($response);
}
} else {
// required field is missing
$response["success"] = 0;
$response["message"] = "Required field(s) is missing";
// echoing JSON response
echo json_encode($response);
}
?>
And this is my db_connect.php
<?php
/**
* A class file to connect to database
*/
class DB_CONNECT {
// constructor
function __construct() {
// connecting to database
$this->connect();
}
// destructor
function __destruct() {
// closing db connection
$this->close();
}
/**
* Function to connect with database
*/
function connect() {
// import database connection variables
require_once __DIR__ . '/db_config.php';
// Connecting to mysql database
$con = mysqli_connect(DB_SERVER, DB_USER, DB_PASSWORD, DB_DATABASE) or die(mysqli_error());
// Selecing database
$db = mysqli_select_db($con,DB_DATABASE) or die(mysqli_error()) or die(mysqli_error());
// returing connection cursor
return $con;
}
/**
* Function to close db connection
*/
function close() {
// closing db connection
}
}
?>
It seems that there's something wrong with my code and this is the error I got
mysqli_query() expects parameter 1 to be mysqli, string given in. Anyone knows how to solve this ? I have searched through StackOverFlow regarding this and tried all the solutions but still cant be solved.
Modify your db connect class to maintain the connection:
class DB_CONNECT {
protected $connection = null;
// constructor
function __construct() {
// connecting to database
$this->connection = $this->connect();
}
// destructor
function __destruct() {
// closing db connection
$this->close();
}
/**
* Function to connect with database
*/
function connect() {
// import database connection variables
require_once __DIR__ . '/db_config.php';
// Connecting to mysql database
$con = mysqli_connect(DB_SERVER, DB_USER, DB_PASSWORD, DB_DATABASE) or die(mysqli_error());
// Selecing database
$db = mysqli_select_db($con,DB_DATABASE) or die(mysqli_error()) or die(mysqli_error());
// returing connection cursor
return $con;
}
public function getConnection() {
return $this->connection;
}
/**
* Function to close db connection
*/
function close() {
// closing db connection
}
}
Then modify your query line to:
if (mysqli_query($db->getConnection(), $result)) {
http://docs.php.net/mysqli_query:
Procedural style
mixed mysqli_query ( mysqli $link , string $query [, int $resultmode = MYSQLI_STORE_RESULT ] )
The first parameter must be a valid/active connection resource that has been returned by mysqli_connect()
As the error said, your first parameter should be the mysqli class, not the query. Like this:
if (mysqli_query($db, $result)) {
use this
mysqli_query($db,$result) //connection first.. query at second position
instead of
mysqli_query($result,$db)
It has to be like this
$result = "INSERT INTO userrequests(userName, contactNumber, userAddress, storeList, requestBody) VALUES('$userName', '$userContact', '$userAddress', '$userStore', '$userRequest')";
// check if row inserted or not
if (mysqli_query($db,$result)) {
}
Closed. This question needs to be more focused. It is not currently accepting answers.
Want to improve this question? Update the question so it focuses on one problem only by editing this post.
Closed 8 years ago.
Improve this question
i am beginer to php and i need your help.i want to make the following code to PDO to have a json output for an android app i am trying to bulit.I tryed a lot of solution but nothing correct came because of the JSON responce.I couldn also find good example and tutorials.Also i am new as i said with php so i am afraid to try complicated scenarios
here is the php code
This is my Config file
db_config.php
<?php
define('DB_USER', "root"); // db user
define('DB_PASSWORD', ""); // db password (mention your db password here)
define('DB_DATABASE', "androidhive"); // database name
define('DB_SERVER', "localhost"); // db server
?>
This is connection file
db_connect.php
<?php
class DB_CONNECT {
// constructor
function __construct() {
// connecting to database
$this->connect();
}
// destructor
function __destruct() {
// closing db connection
$this->close();
}
/**
* Function to connect with database
*/
function connect() {
// import database connection variables
require_once __DIR__ . '/db_config.php';
// Connecting to mysql database
$con = mysql_connect(DB_SERVER, DB_USER, DB_PASSWORD) or die(mysql_error());
// Selecing database
$db = mysql_select_db(DB_DATABASE) or die(mysql_error()) or die(mysql_error());
// returing connection cursor
return $con;
}
/**
* Function to close db connection
*/
function close() {
// closing db connection
mysql_close();
}
}
?>
get_all_products.php
<?php
/*
* Following code will list all the products
*/
// array for JSON response
$response = array();
// include db connect class
require_once __DIR__ . '/db_connect.php';
// connecting to db
$db = new DB_CONNECT();
// get all products from products table
$result = mysql_query("SELECT *FROM products") or die(mysql_error());
// check for empty result
if (mysql_num_rows($result) > 0) {
// looping through all results
// products node
$response["products"] = array();
while ($row = mysql_fetch_array($result)) {
// temp user array
$product = array();
$product["pid"] = $row["pid"];
$product["name"] = $row["name"];
$product["price"] = $row["price"];
$product["created_at"] = $row["created_at"];
$product["updated_at"] = $row["updated_at"];
// push single product into final response array
array_push($response["products"], $product);
}
// success
$response["success"] = 1;
// echoing JSON response
echo json_encode($response);
} else {
// no products found
$response["success"] = 0;
$response["message"] = "No products found";
// echo no users JSON
echo json_encode($response);
}
?>
I know is very easy for someone with experience but i am strungle with it.please help because i have a strick deadline and no time now for deaper search.Thank you
**Would it be helpfull if i post what i have done?I didnt post it for space reason**s
EDIT
THIS IS WHAT I HAVE DONE SO FAR ANY IDEAS?
$db = new PDO("mysql:host=$dbhost;dbname=$dbname;", $dbuser, $dbpass);
$query = "Select * FROM products";
//execute query
try {
$stmt = $db->prepare($query);
$result = $stmt->execute(HAVE NO IDEA!!!!);
}
catch (PDOException $ex) {
$response["success"] = 0;
$response["message"] = "Database Error!";
die(json_encode($response));
}
$rows = $stmt->fetchAll();
if ($rows) {
$response["success"] = 1;
$response["message"] = "Post Available!";
$response["posts"] = array();
foreach ($rows as $row) {
$post = array();
$post["pid"] = $row["pid"];
$post["name"] = $row["name"];
$post["price"] = $row["price"];
//update our repsonse JSON data
array_push($response["posts"], $post);
}
// echoing JSON response
echo json_encode($response);
} else {
$response["success"] = 0;
$response["message"] = "No Post Available!";
die(json_encode($response));
}
?>
Try this approach:
<?php
$response = array()
try {
//connection
$db = new PDO("mysql:host=$dbhost;dbname=$dbname;", $dbuser, $dbpass);
$db->setAttribute(PDO::ATTR_ERRMODE, PDO::ERRMODE_EXCEPTION);
//prepare
$query = "Select * FROM products";
$stmt = $db->prepare($query);
//get resutlt
$result = $stmt->execute();
if ($stmt->rowCount > 0) {
$response["success"] = true;
$response["message"] = "Post Available!";
//populate post array
while($row = $stmt->fetch()){
$response["posts"][] = $row;
}
}else{
$response["success"] = false;
$response["message"] = "No Post Available!";
}
}
catch (PDOException $ex) {
$response["success"] = false;
$response["message"] = "Database Error!";
}
echo json_encode($response);
?>
Prepared statements and stored procedures
using fetch all:
$rows = $stmt->fetchAll();
var_dump($rows);
$response["posts"] = $rows;
I have a Microsoft Access Database, and I am trying to query the table using PHP, and output valid JSON. I have an equivalent code for a MSSQL database, am I am trying to make my code do the same thing, but just for the Access database.
Here is the MSSQL code
$myServer = "server";
$myDB = "db";
$conn = sqlsrv_connect ($myServer, array('Database'=>$myDB));
$sql = "SELECT *
FROM db.dbo.table";
$data = sqlsrv_query ($conn, $sql);
$result = array();
do {
while ($row = sqlsrv_fetch_array ($data, SQLSRV_FETCH_ASSOC)) {
$result[] = $row;
}
} while (sqlsrv_next_result($data));
$json = json_encode ($result);
sqlsrv_free_stmt ($data);
sqlsrv_close ($conn);
Here is what I tried for the MDB file
$dbName = "/filename.mdb";
if (!file_exists($dbName)) {
die("Could not find database file.");
}
$db = odbc_connect("Driver={Microsoft Access Driver (*.mdb)};Dbq=$dbName", $user, $password);
$sql = "SELECT *
FROM cemetery";
$data = $db->query($sql); // I'm getting an error here
$result = array();
// Not sure what do do for this part...
do {
while ($row = fetch($data, SQLSRV_FETCH_ASSOC)) {
$result[] = $row;
}
} while (sqlsrv_next_result($data));
$json = json_encode ($result);
I kind of followed this to try to connect to the database: http://phpmaster.com/using-an-access-database-with-php/
Currently this is giving me a 500 Internal Server Error. I'm expecting a string such as this to be saved in the variable $json
[
{
"col1":"col value",
"col2":"col value",
"col3":"col value",
},
{
"col1":"col value",
"col2":"col value",
"col3":"col value",
},
{
etc...
}
]
Can someone help me port the MSSQL code I have above so I can use it with an MDB database? Thanks for the help!
EDIT: I'm commenting out the lines one by one, and it throws me the 500 error at the line $data = $db->query($sql);. I looked in the error log, and I'm getting the error Call to a member function query() on a non-object. I already have the line extension=php_pdo_odbc.dll uncommented in my php.ini file. Anyone know what the problem could be?
You only need 1 loop,
fetchAll is your iterable friend:
while ($row = $data->fetchAll(SQLSRV_FETCH_ASSOC)) {
$result[] = $row;
}
odbc_connect doesn't return an object, it returns a resource. see (http://php.net/manual/en/function.odbc-connect.php) so you would need to do something like this.
$db = odbc_connect("Driver={Microsoft Access Driver (*.mdb)};Dbq=$dbName", $user, $password);
$oexec = obdc_exec($db,$sql);
$result[] = odbc_fetch_array($oexec);
and then you can iterate over results..
see also:
http://www.php.net/manual/en/function.odbc-fetch-array.php
http://www.php.net/manual/en/function.odbc-exec.php
I finally figured it out.
<?php
// Location of database. For some reason I could only get it to work in
// the same location as the site. It's probably an easy fix though
$dbName = "dbName.mdb";
$tName = "table";
// Throws an error if the database cannot be found
if (!file_exists($dbName)) {
die("Could not find database file.");
}
// Connects to the database
// Assumes there is no username or password
$conn = odbc_connect("Driver={Microsoft Access Driver (*.mdb)};Dbq=$dbName", '', '');
// This is the query
// You have to have each column you select in the format tableName.[ColumnName]
$sql = "SELECT $tName.[ColumnOne], $tName.[ColumnTwo], etc...
FROM $dbName.$tName";
// Runs the query above in the table
$rs = odbc_exec($conn, $sql);
// This message is displayed if the query has an error in it
if (!$rs) {
exit("There is an error in the SQL!");
}
$data = array();
$i = 0;
// Grabs all the rows, saves it in $data
while( $row = odbc_fetch_array($rs) ) {
$data[$i] = $row;
$i++;
}
odbc_close($conn); // Closes the connection
$json = json_encode($data); // Generates the JSON, saves it in a variable
?>
I use this code to get results from an ODBC query into a JSON array:
$response = null;
$conn = null;
try {
$odbc_name = 'myODBC'; //<-ODBC connectyion name as is in the Windows "Data Sources (ODBC) administrator"
$sql_query = "SELECT * FROM table;";
$conn = odbc_connect($odbc_name, 'user', 'pass');
$result = odbc_exec($conn, $sql_query);
//this will show all results:
//echo odbc_result_all($result);
//this will fetch row by row and allows to change column name, format, etc:
while( $row = odbc_fetch_array($result) ) {
$json['cod_sistema'] = $row['cod_sistema'];
$json['sistema'] = $row['sistema'];
$json['cod_subsistema'] = $row['cod_subsistema'];
$json['sub_sistema'] = $row['sub_sistema'];
$json['cod_funcion'] = $row['cod_funcion'];
$json['funcion'] = $row['funcion'];
$json['func_desc_abrev'] = $row['desc_abreviada'];
$json['cod_tipo_funcion'] = $row['cod_tipo_funcion'];
$response[] = array('funcionalidad' => $json);
}
odbc_free_result($result); //<- Release used resources
} catch (Exception $e) {
$response = array('resultado' => 'err', 'detalle' => $e->getMessage());
echo 'ERROR: ', $e->getMessage(), "\n";
}
odbc_close($conn);
return $response;
And finnally encoding the response in JSON format:
echo json_encode($response);