//FIRST WAY
$dbConf = new DBConnection();
$databaseURL = $dbConf->get_databaseURL();
$databaseUName = $dbConf->get_databaseUName();
$databasePWord = $dbConf->get_databasePWord();
$databaseName = $dbConf->get_databaseName();
$connection = mysql_connect($databaseURL, $databaseUName, $databasePWord);
$db = mysql_select_db($databaseName, $connection);
//$stmt = mssql_init("sp_GetObjectMasterData", $connection);
$rs = mysql_query("CALL sp_GetObjectMasterData($p_user_id, $p_org_id, $p_ret_messaage, $p_ret_code)");
if($rs) {
while($row = mysql_fetch_assoc($rs))
{
echo $row;
}
return "Object ".$p_ret_messaage;
} else {
return "FALSE DATA";
}
$mysqli = new mysqli( "XXXXXXXXX", "XXXXXXXX", "XXXXXXXX", "XXXXXXXXXXX" );
$res = $mysqli->multi_query( "CALL sp_GetObjectMasterData($p_user_id, $p_org_id, @message, @code)" );
if($res) {
$tableObjectArray = array();
$tableArray = array();
$results = 0;
$countObj = 0;
do {
if ($result = $mysqli->store_result()) {
while( $row = $result->fetch_row() ) {
$tableObjectArray[$countObj] = $row[0];
$tableArray[$countObj] = $row[1];
$countObj++;
}
$result->close();
if( $mysqli->more_results() ) ;
}
} while( $mysqli->next_result() );
if(count($tableObjectArray)) {
$count = 0;
$tempTableArray = array();
foreach($tableArray as $selectionTable) {
$selectionDataArray = explode('~', $selectionTable);
$tempSelectionDataArray = array();
for($i = 0; $i < count($selectionDataArray) - 1; $i++) {
$selectionData = explode('|', $selectionDataArray[$i]);
$objectContainer = array();
$objectContainer[0] = $selectionData[0];
$objectContainer[1] = $selectionData[1].'-'.$selectionData[2];
$tempSelectionDataArray[$i] = $objectContainer;
}
$tempTableArray[$tableObjectArray[$count]] = $tempSelectionDataArray;
$count++;
}
$mysqli->close();
return json_encode($tempTableArray);
} else {
$mysqli->close();
return "false";
}
} else {
$mysqli->close();
return "false";
}
//SECOND WAY
/*
$mysql = mysql_connect('174.122.129.141', 'henrik_mcgm', 'mcgm8899', false, 65536);
mysql_select_db('henrik_mcgm', $mysql);
$rs = mysql_query("CALL henrik_mcgm.sp_GetObjectMasterData(212233385,6335572, @message, @code)");
echo $rs;
while($row = mysql_fetch_assoc($rs))
{
echo $row;
}
*/
//THIRD WAY
/* prepare the statement resource
$dbConf = new DBConnection();
$databaseURL = $dbConf->get_databaseURL();
$databaseUName = $dbConf->get_databaseUName();
$databasePWord = $dbConf->get_databasePWord();
$databaseName = $dbConf->get_databaseName();
$connection = mysql_connect($databaseURL, $databaseUName, $databasePWord);
$db = mysql_select_db($databaseName, $connection);
$stmt = mssql_init("sp_GetObjectMasterData", $connection);
$p_ret_messaage = "";
$p_ret_code = 0;
mssql_bind($stmt, "@p_user_id", $p_user_id, SQLINT4);
mssql_bind($stmt, "@p_org_id", $p_org_id, SQLINT4); //SQLVARCHAR
mssql_bind($stmt, "@p_ret_messaage", $p_ret_messaage, SQLVARCHAR);
mssql_bind($stmt, "@p_ret_code", $p_ret_code, SQLINT4); //SQLVARCHAR
$result = mssql_execute($stmt);
echo $p_ret_messaage;
echo $p_ret_code;
// Fetch Return Data And Place Into Array For Access
$procedureResponseData = mssql_fetch_object($result);
mysql_close($connection);
return 'Response: '.$procedureResponseData; */
//LOCAL TEST
/*
$mysql = mysql_connect('localhost', '', '', false, 65536); //,false,65536 // add this to fix issue with recordsets
mysql_select_db('test', $mysql);
print '<h3>MYSQL: simple select</h3>';
$rs = mysql_query('SELECT * FROM users;');
while($row = mysql_fetch_assoc($rs))
{
echo $row['users_id'];
echo $row['first_name'];
echo $row['last_name'];
}
print '<h3>MYSQL: calling store procedure with out variables</h3>';
$rs = mysql_query('CALL get_user(1, @first, @last)');
$rs = mysql_query('SELECT @first, @last');
while($row = mysql_fetch_assoc($rs))
{
echo $row;
}
print '<h3>MYSQL: calling store procedure returning a recordset – doesn\'t work</h3>';
$rs = mysql_query('CALL get_users()');
while($row = mysql_fetch_assoc($rs))
{
echo $row;
}
*/
/*
// MYSQLI
$mysqli = new mysqli('localhost', '', '', 'test');
$rs = $mysqli->query( 'SELECT * FROM users;' );
while($row = $rs->fetch_object())
{
print_r($row);
}
$rs = $mysqli->query( 'CALL get_user(1, @first, @last)' );
$rs = $mysqli->query( 'SELECT @first, @last' );
while($row = $rs->fetch_object())
{
print_r($row);
}
$rs = $mysqli->query( 'CALL get_users()' );
while($row = $rs->fetch_object())
{
print_r($row);
}
*/
$dbConf = new DBConnection();
$databaseURL = $dbConf->get_databaseURL();
$databaseUName = $dbConf->get_databaseUName();
$databasePWord = $dbConf->get_databasePWord();
$databaseName = $dbConf->get_databaseName();
$connection = mysql_connect($databaseURL, $databaseUName, $databasePWord);
$db = mysql_select_db($databaseName, $connection);
//$stmt = mssql_init("sp_GetObjectMasterData", $connection);
$rs = mysql_query("CALL sp_GetObjectMasterData($p_user_id, $p_org_id, $p_ret_messaage, $p_ret_code)");
if($rs) {
while($row = mysql_fetch_assoc($rs))
{
echo $row;
}
return "Object ".$p_ret_messaage;
} else {
return "FALSE DATA";
}
$mysqli = new mysqli( "XXXXXXXXX", "XXXXXXXX", "XXXXXXXX", "XXXXXXXXXXX" );
$res = $mysqli->multi_query( "CALL sp_GetObjectMasterData($p_user_id, $p_org_id, @message, @code)" );
if($res) {
$tableObjectArray = array();
$tableArray = array();
$results = 0;
$countObj = 0;
do {
if ($result = $mysqli->store_result()) {
while( $row = $result->fetch_row() ) {
$tableObjectArray[$countObj] = $row[0];
$tableArray[$countObj] = $row[1];
$countObj++;
}
$result->close();
if( $mysqli->more_results() ) ;
}
} while( $mysqli->next_result() );
if(count($tableObjectArray)) {
$count = 0;
$tempTableArray = array();
foreach($tableArray as $selectionTable) {
$selectionDataArray = explode('~', $selectionTable);
$tempSelectionDataArray = array();
for($i = 0; $i < count($selectionDataArray) - 1; $i++) {
$selectionData = explode('|', $selectionDataArray[$i]);
$objectContainer = array();
$objectContainer[0] = $selectionData[0];
$objectContainer[1] = $selectionData[1].'-'.$selectionData[2];
$tempSelectionDataArray[$i] = $objectContainer;
}
$tempTableArray[$tableObjectArray[$count]] = $tempSelectionDataArray;
$count++;
}
$mysqli->close();
return json_encode($tempTableArray);
} else {
$mysqli->close();
return "false";
}
} else {
$mysqli->close();
return "false";
}
//SECOND WAY
/*
$mysql = mysql_connect('174.122.129.141', 'henrik_mcgm', 'mcgm8899', false, 65536);
mysql_select_db('henrik_mcgm', $mysql);
$rs = mysql_query("CALL henrik_mcgm.sp_GetObjectMasterData(212233385,6335572, @message, @code)");
echo $rs;
while($row = mysql_fetch_assoc($rs))
{
echo $row;
}
*/
//THIRD WAY
/* prepare the statement resource
$dbConf = new DBConnection();
$databaseURL = $dbConf->get_databaseURL();
$databaseUName = $dbConf->get_databaseUName();
$databasePWord = $dbConf->get_databasePWord();
$databaseName = $dbConf->get_databaseName();
$connection = mysql_connect($databaseURL, $databaseUName, $databasePWord);
$db = mysql_select_db($databaseName, $connection);
$stmt = mssql_init("sp_GetObjectMasterData", $connection);
$p_ret_messaage = "";
$p_ret_code = 0;
mssql_bind($stmt, "@p_user_id", $p_user_id, SQLINT4);
mssql_bind($stmt, "@p_org_id", $p_org_id, SQLINT4); //SQLVARCHAR
mssql_bind($stmt, "@p_ret_messaage", $p_ret_messaage, SQLVARCHAR);
mssql_bind($stmt, "@p_ret_code", $p_ret_code, SQLINT4); //SQLVARCHAR
$result = mssql_execute($stmt);
echo $p_ret_messaage;
echo $p_ret_code;
// Fetch Return Data And Place Into Array For Access
$procedureResponseData = mssql_fetch_object($result);
mysql_close($connection);
return 'Response: '.$procedureResponseData; */
//LOCAL TEST
/*
$mysql = mysql_connect('localhost', '', '', false, 65536); //,false,65536 // add this to fix issue with recordsets
mysql_select_db('test', $mysql);
print '<h3>MYSQL: simple select</h3>';
$rs = mysql_query('SELECT * FROM users;');
while($row = mysql_fetch_assoc($rs))
{
echo $row['users_id'];
echo $row['first_name'];
echo $row['last_name'];
}
print '<h3>MYSQL: calling store procedure with out variables</h3>';
$rs = mysql_query('CALL get_user(1, @first, @last)');
$rs = mysql_query('SELECT @first, @last');
while($row = mysql_fetch_assoc($rs))
{
echo $row;
}
print '<h3>MYSQL: calling store procedure returning a recordset – doesn\'t work</h3>';
$rs = mysql_query('CALL get_users()');
while($row = mysql_fetch_assoc($rs))
{
echo $row;
}
*/
/*
// MYSQLI
$mysqli = new mysqli('localhost', '', '', 'test');
$rs = $mysqli->query( 'SELECT * FROM users;' );
while($row = $rs->fetch_object())
{
print_r($row);
}
$rs = $mysqli->query( 'CALL get_user(1, @first, @last)' );
$rs = $mysqli->query( 'SELECT @first, @last' );
while($row = $rs->fetch_object())
{
print_r($row);
}
$rs = $mysqli->query( 'CALL get_users()' );
while($row = $rs->fetch_object())
{
print_r($row);
}
*/
$procedureResponseData = "|1|M|Manhole~|2|L|Lamp hole~|3|G|Ghost Node~|4|O|Outfall~|5|S|Storm Overflow~|6|P|Pumping Station~|7|W|WWTF~|8|Z|Manhole of RM~|9|J|Junction Box~|10|B|Balancing Chamber~|11|V|Vent Shaft~#
|1|M|Manhole~|2|L|Lamp hole~|3|G|Ghost Node~|4|O|Outfall~|5|S|Storm Overflow~|6|P|Pumping Station~|7|W|WWTF~|8|Z|Manhole of RM~|9|J|Junction Box~|10|B|Balancing Chamber~|11|V|Vent Shaft~#
|1|M|Manhole~|2|L|Lamp hole~|3|G|Ghost Node~|4|O|Outfall~|5|S|Storm Overflow~|6|P|Pumping Station~|7|W|WWTF~|8|Z|Manhole of RM~|9|J|Junction Box~|10|B|Balancing Chamber~|11|V|Vent Shaft~#
|1|M|Manhole~|2|L|Lamp hole~|3|G|Ghost Node~|4|O|Outfall~|5|S|Storm Overflow~|6|P|Pumping Station~|7|W|WWTF~|8|Z|Manhole of RM~|9|J|Junction Box~|10|B|Balancing Chamber~|11|V|Vent Shaft~#
|1|M|Manhole~|2|L|Lamp hole~|3|G|Ghost Node~|4|O|Outfall~|5|S|Storm Overflow~|6|P|Pumping Station~|7|W|WWTF~|8|Z|Manhole of RM~|9|J|Junction Box~|10|B|Balancing Chamber~|11|V|Vent Shaft~#
|1|M|Manhole~|2|L|Lamp hole~|3|G|Ghost Node~|4|O|Outfall~|5|S|Storm Overflow~|6|P|Pumping Station~|7|W|WWTF~|8|Z|Manhole of RM~|9|J|Junction Box~|10|B|Balancing Chamber~|11|V|Vent Shaft~#
|1|M|Manhole~|2|L|Lamp hole~|3|G|Ghost Node~|4|O|Outfall~|5|S|Storm Overflow~|6|P|Pumping Station~|7|W|WWTF~|8|Z|Manhole of RM~|9|J|Junction Box~|10|B|Balancing Chamber~|11|V|Vent Shaft~#
|1|M|Manhole~|2|L|Lamp hole~|3|G|Ghost Node~|4|O|Outfall~|5|S|Storm Overflow~|6|P|Pumping Station~|7|W|WWTF~|8|Z|Manhole of RM~|9|J|Junction Box~|10|B|Balancing Chamber~|11|V|Vent Shaft~";
$tableObjectArray = array(0 => 'object_node_status_master', 1 => 'object_node_type_master', 2 => 'object_ward_master', 3 => 'object_manhole_shape_master',
4 => 'object_soffit_master', 5 => 'object_cover_shape_master', 6 => 'object_connection_code_master', 7 => 'object_lining_material_code_master',
8 => 'object_pipe_material_code_master', 9 => 'object_pipe_shape_master');
$tableArray = explode('#', $procedureResponseData);
$tempTableArray = array();
$count = 0;
foreach($tableArray as $selectionTable) {
$selectionDataArray = explode('~', $selectionTable);
$tempSelectionDataArray = array();
for($i = 0; $i < count($selectionDataArray) - 1; $i++) {
$selectionData = explode('|', $selectionDataArray[$i]);
$objectContainer = array();
$objectContainer[0] = $selectionData[1];
$objectContainer[1] = $selectionData[2].'-'.$selectionData[3];
$tempSelectionDataArray[$i] = $objectContainer;
}
$tempTableArray[$tableObjectArray[$count]] = $tempSelectionDataArray;
$count++;
}
return json_encode($tempTableArray);
0 comments:
Post a Comment