<?php 
error_reporting(-1);
		ini_set('display_errors', 1);
//$old_path = getcwd();
//chdir('/etc');
//$output = shell_exec('isql -v FB_SAMPLE');
//chdir($old_path);
//echo "<pre>"; print_r($output); exit;
//die('exit');
?>


<!DOCTYPE>
<html>
<head>
	<title>ODBC Connection</title>
	<link rel="stylesheet" href="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.7/css/bootstrap.min.css">
</head>
<body>

<div class="container">
 <form method="post" action="">
 <div class="col-sm-6">
 	<textarea rows=10 cols="50" name="query"></textarea>
 </div>
 <div class="col-sm-2">
 <input type="submit" name="run_query" value="run">
 </div>
 </form>


<?php

/*
PHP MSSQL Example

Replace data_source_name with the name of your data source.
Replace database_username and database_password
with the SQL Server database username and password.
*/
$data_source='FB_SAMPLE';
$user='OPERATOR';
$password='rotarepo';
// Connect to the data source and get a handle for that connection.
$conn=odbc_connect($data_source,$user,$password);
echo "stull";

if (!$conn){

	    if (phpversion() < '4.0'){
			echo "2";
	      exit("Connection Failed: . $php_errormsg" );
	    }
	    else{
			echo "3";
	      exit("Connection Failed:" . odbc_errormsg() );
	    }
	}
	else
	{
		echo "connect successfully";
	}



// This query generates a result set with one record in it.
$sql=$_POST['query'];

# Execute the statement.
$rs=odbc_exec($conn,$sql);
while (odbc_fetch_row($rs)){
			    $col1=odbc_result_all($rs, "test_col");
			   // echo "$col1\n";
			    echo "<pre>"; print_r(odbc_fetch_row($rs)); exit;
			}

//echo "<pre>"; print_r(odbc_fetch_row($rs)); exit;
// Fetch and display the result set value.
if (!$rs){
    exit("Error in SQL");
}
?>

 <div class="col-sm-4">
 	<textarea rows=10 cols="50">
 	<?php 

 	/*if (!$conn){
	    if (phpversion() < '4.0'){
	      exit("Connection Failed: . $php_errormsg" );
	    }
	    else{
	      exit("Connection Failed:" . odbc_errormsg() );
	    }
	}*/

 	if (!$rs){
		    exit("Error in SQL");
		}
	?> 
</textarea>
 </div>

</div>
 <br>
 <div class="container">

 <div class="col-sm-12" >
 	<textarea rows=10 cols="145"> 
 		<?php 
 			/*while (odbc_fetch_row($rs)){
			    $col1=odbc_result($rs, "test_col");
			    echo "$col1\n";
			}*/
 		?> 
 	</textarea>
 </div>
 </div>
<?php 
// Disconnect the database from the database handle.
odbc_close($conn);
?>


</body>
</html>