I am trying to execute the following query in my PHP file.
show create table test.account;
When I echo the response I am only getting the first word of the query i.e. CREATE. I surrounded the whole query by single quotes but when I echo the response I only get the response from first single quote to next single quote (next single quote is used for some default string), not the whole query.
Following is my API interface code -
@GET("createQueries.php/")
Call<String> loadCreateQueries(@Query("tableName") String tableName);
My PHP code -
<?php
include_once 'db_functions.php';
$db = new DB_Functions();
require_once 'config.php';
// connecting to mysql
$con = mysqli_connect(DB_HOST, DB_USER, DB_PASSWORD);
if ( !$con){
echo "Database Connection Error";
}
// selecting database
$select = mysqli_select_db($con,DB_DATABASE);
if ( !$select){
echo "Database Selection Error";
}
$tableName = $_GET["tableName"];
$result = mysqli_query($con, "SHOW CREATE TABLE test.".$tableName);
if ($result != false) {
$create_query = "'{";
while ($row = mysqli_fetch_assoc($result)) {
$fields = array_values($row);
$create_query = $create_query.$fields[1];
}
$create_query = $create_query."}'";
echo $create_query;
} else {
echo "Table not in server";
}
?>
Response
{CREATE TABLE `account` (
`id` int(11) NOT NULL AUTO_INCREMENT,
`name` varchar(100) DEFAULT NULL,
`amount` float DEFAULT NULL,
`interestRate` float DEFAULT NULL,
`totalInterestReceived` float DEFAULT
Client code -
public void createTable() {
if (tableNames.length > tableIndex) {
NetworkUtil.getAPI(getApplicationContext()).loadCreateQueries(tableNames[tableIndex]).enqueue(new Callback<JsonElement>() {
@Override
public void onResponse(Call<JsonElement> call, Response<JsonElement> response) {
progressDialog.dismiss();
if (response.isSuccessful()) {
String query = response.body().getAsString();
Log.d("Create Query - ", query);
} else System.out.println(response.errorBody());
}
@Override
public void onFailure(Call<JsonElement> call, Throwable t) {
t.printStackTrace();
}
});
}
}