domingo, 23 de junio de 2019

difference $_ POST $HTTP_RAW_POST_DATA

  1. $_POST contains URL encoded (application/www-url-encoded) variables that are posted to your script and PHP decodes them for you. You use this one when you deal with HTML FORM data.
  2. file_get_contents("php://input") - gets the raw POST data and you need to use this when you write APIs and need XML/JSON/... input that cannot be decoded to $_POST by PHP.
  3. $HTTP_RAW_POST_DATA - in theory it is the same as the above but depends on php.ini.
I always use method #2 instead of #3 when I need non application/www-url-encoded input.

Receive JSON POST with PHP

Try;
$data = json_decode(file_get_contents('php://input'), true);
print_r($data);
echo $data["operacion"];
From your json and your code, it looks like you have spelled the word operation correctly on your end, but it isn't in the json.
EDIT
Maybe also worth trying to echo the json string from php://input.
echo file_get_contents('php://input');

viernes, 21 de junio de 2019

MSSQL PDO

Go to step 2

Go to step 3
Check out the PHP Driver on GitHub
# yum install php php-mcrypt php-cli php-gd php-curl php-mysql php-ldap php-zip php-fileinfo


# yum install https://dl.fedoraproject.org/pub/epel/epel-release-latest-7.noarch.rpm
# yum install http://rpms.remirepo.net/enterprise/remi-release-7.rpm

# yum install yum-utils
# yum-config-manager --enable remi-php72   [Install PHP 7.2]


yum install php php-cli php-pdo php-xml php-pear php-devel re2c gcc-c++ gcc

sudo yum install php-sqlsrv php-pdo_sqlsrv


# yum install php php-mcrypt php-cli php-gd php-curl php-mysql php-ldap php-zip php-fileinfo


https://www.microsoft.com/en-us/sql-server/developer-get-started/php/rhel



<?php

    $serverName = "148.103.164.69";
    $connectionOptions = array(
        "Database" => "master",
        "Uid" => "sa",
        "PWD" => "123"
    );
    //Establishes the connection
  $conn = sqlsrv_connect($serverName, $connectionOptions);
    if($conn) {
        $sql = "SELECT * FROM TestSchema.Employees;";
       //$sql="SELECT @@VERSION  as ver";
$stmt = sqlsrv_query( $conn, $sql );
if( $stmt === false) {
    die( print_r( sqlsrv_errors(), true) );
}

while( $row = sqlsrv_fetch_array( $stmt, SQLSRV_FETCH_ASSOC) ) {
      //echo $row['optname']."<br />";
       echo $row['Id']."\n";
      echo $row['Name']."\n";
            echo $row['Location']."\n";

}

sqlsrv_free_stmt( $stmt);
}

if( $conn === false ) {
     die( print_r( sqlsrv_errors(), true));
}

?>
sqlcmd -S 148.103.164.69 -U sa -P 123 -d master -Q "CREATE SCHEMA TestSchema;"
sqlcmd -S 148.103.164.69 -U sa -P 123  -d master -Q "CREATE TABLE TestSchema.Employees (Id INT IDENTITY(1,1) NOT NULL PRIMARY KEY, Name NVARCHAR(50), Location NVARCHAR(50));"


sqlcmd -S 148.103.164.69 -U sa -P 123  -d master -Q "INSERT INTO TestSchema.Employees (Name, Location) VALUES (N'Jared',N'Australia'), (N'Nikita', N'India'), (N'Tom', N'Germany');"


sqlcmd -S 148.103.164.69 -U sa -P 123  -d master -Q "SELECT * FROM TestSchema.Employees;"