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;"


miércoles, 19 de junio de 2019

Composer Centos 7

Install Composer using cURL
# sudo curl -sS https://getcomposer.org/installer | php
Want to make Composer globally accessible?
# mv composer.phar /usr/local/bin/composer

sábado, 9 de marzo de 2019

preg_match

Simple regex

Regex quick reference
[abc]     A single character: a, b or c
[^abc]     Any single character but a, b, or c
[a-z]     Any single character in the range a-z
[a-zA-Z]     Any single character in the range a-z or A-Z
^     Start of line
$     End of line
\A     Start of string
\z     End of string
.     Any single character
\s     Any whitespace character
\S     Any non-whitespace character
\d     Any digit
\D     Any non-digit
\w     Any word character (letter, number, underscore)
\W     Any non-word character
\b     Any word boundary character
(...)     Capture everything enclosed
(a|b)     a or b
a?     Zero or one of a
a*     Zero or more of a
a+     One or more of a
a{3}     Exactly 3 of a
a{3,}     3 or more of a
a{3,6}     Between 3 and 6 of a

options: i case insensitive m make dot match newlines x ignore whitespace in regex o perform #{...} substitutions only onc

http://php.net/manual/en/function.preg-match.php

lunes, 4 de marzo de 2019

jueves, 31 de enero de 2019

PHP: How to send HTTP response code?

378
I just found this question and thought it needs a more comprehensive answer:
As of PHP 5.4 there are three methods to accomplish this:

Assembling the response code on your own (PHP >= 4.0)

The header() function has a special use-case that detects a HTTP response line and lets you replace that with a custom one
header("HTTP/1.1 200 OK");
However, this requires special treatment for (Fast)CGI PHP:
$sapi_type = php_sapi_name();
if (substr($sapi_type, 0, 3) == 'cgi')
    header("Status: 404 Not Found");
else
    header("HTTP/1.1 404 Not Found");
Note: According to the HTTP RFC, the reason phrase can be any custom string (that conforms to the standard), but for the sake of client compatibility I do not recommend putting a random string there.
Note: php_sapi_name() requires PHP 4.0.1

3rd argument to header function (PHP >= 4.3)

There are obviously a few problems when using that first variant. The biggest of which I think is that it is partly parsed by PHP or the web server and poorly documented.
Since 4.3, the header function has a 3rd argument that lets you set the response code somewhat comfortably, but using it requires the first argument to be a non-empty string. Here are two options:
header(':', true, 404);
header('X-PHP-Response-Code: 404', true, 404);
I recommend the 2nd one. The first does work on all browsers I have tested, but some minor browsers or web crawlers may have a problem with a header line that only contains a colon. The header field name in the 2nd. variant is of course not standardized in any way and could be modified, I just chose a hopefully descriptive name.

http_response_code function (PHP >= 5.4)

The http_response_code() function was introduced in PHP 5.4, and it made things a lot easier.
http_response_code(404);
That's all.

martes, 20 de noviembre de 2018

reading a file and printing specific values

<?php
// get contents of a file into a string
$filename = "./areacode.log";
$handle = fopen($filename, "r");
$contents = fread($handle, filesize($filename));
fclose($handle);

$elements=explode("\n",$contents) ;
foreach($elements as $value) {
if (stristr($value,"California ")) {   // If  Number  California  is found it will print all values co Calif
echo "$value<br>";
}

}
?>

Original File
Alabama(1)251

Alabama(1)256

Alabama(1)334

Alaska(1)907

Arizona (1)480

Arizona (1)520

Arizona (1)602

Arizona (1)623

Arizona (1)928

Arkansas(1)479

Arkansas(1)501

Arkansas(1)870

California (1)209

California (1)213

California (1)310

California (1)323

California (1)408

California (1)415


domingo, 11 de noviembre de 2018

json encode y decode

<?php

$arr=array(6000=>"blocked",6001=>40000);

$info=json_encode($arr);

print_r($info);

$info=json_decode($info,true);

foreach($info as $key=>$value){
echo "<br><br>";
echo  "$key=>$value <br>";
}


?>