file()

file() reads a text file as a line feed delimited array. Typical use cases are parsing log files and importing line-delimited text lists.

a.txt

サンバイオ
アンジェス
オンコリス
ラクオリア
シンバイオ
var_dump(file(__DIR__ . '/a.txt'));

echo "<br>";

var_dump(file(__DIR__ . '/a.txt', FILE_IGNORE_NEW_LINES));

echo "<br>";

var_dump(file(__DIR__ . '/a.txt', FILE_SKIP_EMPTY_LINES));

echo "<br>";

var_dump(file(__DIR__ . '/a.txt', FILE_IGNORE_NEW_LINES | FILE_SKIP_EMPTY_LINES));

array(6) { [0]=> string(17) “サンバイオ ” [1]=> string(17) “アンジェス ” [2]=> string(2) ” ” [3]=> string(17) “オンコリス ” [4]=> string(17) “ラクオリア ” [5]=> string(15) “シンバイオ” }
array(6) { [0]=> string(15) “サンバイオ” [1]=> string(15) “アンジェス” [2]=> string(0) “” [3]=> string(15) “オンコリス” [4]=> string(15) “ラクオリア” [5]=> string(15) “シンバイオ” }
array(6) { [0]=> string(17) “サンバイオ ” [1]=> string(17) “アンジェス ” [2]=> string(2) ” ” [3]=> string(17) “オンコリス ” [4]=> string(17) “ラクオリア ” [5]=> string(15) “シンバイオ” }
array(5) { [0]=> string(15) “サンバイオ” [1]=> string(15) “アンジェス” [2]=> string(15) “オンコリス” [3]=> string(15) “ラクオリア” [4]=> string(15) “シンバイオ” }

なんだーこれ、わかったような、わかってないような。。

readfile()

まず、file_get_contents()

$image = file_get_contents(__DIR__ . '/sample.jpg');
header('Content-Type: image/jpg');
header('Content-Length: '. count($image));
header('Content-Disposition: attachment; filename=sample.jpg');

echo $image;

続いて、readfile()

$filename = (__DIR__ . '/sample.jpg');
header('Content-Type: application/octet-stream');
header('Content-Length: ' . filesize($filename));
header('Content-Disposition: attachment; filename=sample.jpg');

readfile($filename);

いいですねー
まあ、フレームワークによって作法があるようです。

File Access

file_get_contents()
Want to read the whole file

readfile()
Want to output the entire contents of the file

file()
want to read line-by-line text file as an array

fopen() + fread()
Want to read the file byte by byte

SplFileObject class
want to read CSV

SplFileObject class
want to operate object-oriented

サンプルのjsonデータを使ってみます。

{
    "glossary": {
        "title": "example glossary",
		"GlossDiv": {
            "title": "S",
			"GlossList": {
                "GlossEntry": {
                    "ID": "SGML",
					"SortAs": "SGML",
					"GlossTerm": "Standard Generalized Markup Language",
					"Acronym": "SGML",
					"Abbrev": "ISO 8879:1986",
					"GlossDef": {
                        "para": "A meta-markup language, used to create markup languages such as DocBook.",
						"GlossSeeAlso": ["GML", "XML"]
                    },
					"GlossSee": "markup"
                }
            }
        }
    }
}
$json = file_get_contents(__DIR__ . '/sample.json');
if($json === false){
	echo ('file not found.');
} else {
	$data = json_decode($json, true);
	var_dump($data);
}

file_get_contents() は、使用頻度高いです。

statement handle

A statement handle is a data object that describes on SQL statement and tracks its execution. You can execute a statement only by allocating a statement handle.

SQLAllocHandle() (with HandleType set to SQL_HANDLE_STMT) allocates a statement handle to describe an SQL statement. Descriptions of SQL statements include information such as statement attributes, SQL statement text, dynamic parameters, cursor information, dynamic arguments and column bindings, result values, and status information. Each statement handle associates a connection with statement that the handle describes.

What is bind?

Bind variables are variables used in SQL statements, which are languages that perform writing and query to a database.

When making similar processing requests repeatedly while changing only a certain number to the database, if you re-set the number of the SQL statement each time, many types of SQL statements will be processed, which is inefficient. In such a case, if the bind variable is used, the database recognizes that “the same SQL statement is repeated processed under another condition”, so that the processing time can be efficiently improved and the processing time can be shortened.

In the case of Oracle Database, bind variables are represented by adding a colon(:) to the beginning of the variable name(e.g :number)

$sql = ‘select name, breed, weight from animals where weight > ? and weight < ?'; $conn = db2_connect($database, $user, $password); $stmt = db2_prepare($conn, $sql); $lower_limit = 1; db2_bind_param($stmt, 1, "lower_limit", DB2_PARAM_IN); db2_bind_param($stmt, 2, "upper_limit", DB2_PARAM_IN); $upper_limit = 15.0; if(db2_execute($stmt)){ while ($row = db2_fetch_array($stmt)){ print "{$row[0]}, {$row[1]}, {$row[2]}\n"; } } [/php]

Database Handles

Database handle are fully encapsulated objects. Transactions from one database handle do not cross over or leak with one another.

$rc = $dbh->do($statement) || die $dbh->errstr;
$rc = $dbh->do($statement, \%attr) ||die $dbh->errstr;

$rv = $dbh->do($statement, \%attr,@bind_values) || ...

my $rows =$dbh->do(q{
	DELETE FROM table
},undef,'DONE') || die $dbh->errstr;

$art_ref =$dbh->selectall_arrayref($statement);
$ary_ref = $dbh->selectall_arrayref($statement, \%attr);
$ary_ref = $dbh->selectall_arrayref($statement, \%attr, @bind_values);

$sth = $dbh->prepare($statement) || die $dbh->errstr;
$sth = $dbh->prepare($statement, \%attr) ||die $dbh->errstr;

my $sth =$dbh->@prepare("SELECT * from mytable where name like ?");
$sth->bind_param(1, 'J%');

$sth = $dbh->prepare_cached($statement) || die $dbh->errstr;
$sth = $dbh->prepare_cached($statement, \%attr) || die $dbh->errstr;

すげー、相当頑張らねーと。。。

モダンな開発環境とは何か?

とにかく今のプロジェクトのクオリティを上げることが最優先、と考えていたが、思っていたより直ぐに「モダンな開発環境とは何か?」という問いに直面してしまった。

自分なりに整理してみる。
まず、技術トレンドに乗っている
これが大事では。レガシーなシステムは切り離して、トレンドを忠実に追うこと。そのためには、まずそういう環境に身を置くことが大事。ちゃんと技術トレンドに沿っているエンジニアと一緒に仕事をしないといけない。
– 言語はpython
– クラウドはaws
– mac

積み重ねだと思うが、結構大事かも。

次に、、、
積極的に新しい技術を学んでいけ
やっぱりこれは大事なんじゃないか。。と思い始めた。

結果的にそれが価値に繋がるのでは。

最近思うのは、競争相手は中国やインドなどのエンジニアだということ。働き方改革など悠著な事を言っている場合ではありませんね。

Window function

The window function performs calculations across a set of table rows that are somehow related to the current row. This is similar to the form of calculation performed by aggregate functions. However, unlike regular aggregation functions, the use of window functions does not group rows into a single output row. Each row maintains its own identity.

Windows functions perform aggregation processing(ranking, etc) on acquired(SELECT) data. It can be said that it is an essential function in the recent trend of big data and OLAP.

SELECT
  Start_station_name,
  Duration,
  SUM(Duration) OVER (PARTITION BY Start_station_name ORDER BY Start_time) AS running_total
 FROM
  trip_histories
 WHERE
  Start_time < '2019-01-30'
 LIMIT 10;

SELECT
 Start_station_name,
 Duration,
 SUM(Duration) OVER (PARTITION BY Start_station_name) AS running_total,
 COUNT(Duration) OVER (PARTITION BY Start_station_name) AS running_count,
 AVG(Duration) OVER (PARTITION BY Start_station_name) AS running_avg
FROM
 trip_histories
WHERE
 Start_time < '2019-04-30'
LIMIT 10;

SELECT
 ROW_NUMBER() OVER (order by Start_time DESC) AS row_num,
 Start_station_name,
 Start_time,
 Duration
FROM
 trip_histories
WHERE
 Start_time < '2019-04-30'
LIMIT 10;

なるほどー、これは数こなさないとな~

What is CTE?

What is CTE?
– CTE is a so-called “recursive query”
– The WOTH clause has become available
 → Implemented on other RDMS(PostgreSQL, Oracle etc)
– Hierarchical queries can be written very easily
 → In the past, it had to be nested using subueries.

WITH RECURSIVE Hatoyama AS
(
 select id, last_name, first_name from family
   where last_name= "鳩山" and first_name="和夫"
 union all
   select child.id, child.last_name, child.first_name
   from family as child, Hatoyama
    where Hatoyama.id = child.parent_id
)
select * from Hatoyama;

WITH Yoshida as
(
	select id, last_name, first_name from family
	  where last_name="吉田" and parent id is null
	union all
	  select child.id, child.last_name, child.first_name
	  from family as child, Yoshida
	  where yoshida.id= child.parent_id
)
select * from Yoshida;

select文が階層化しないようにできるわけね。

apache 2.4.39 ~apacheのバージョンって何が違うの?

[vagrant@localhost ~]$ httpd -v
Server version: Apache/2.2.15 (Unix)
Server built: Jun 19 2018 15:45:13
[vagrant@localhost ~]$ apachectl -v
Server version: Apache/2.2.15 (Unix)
Server built: Jun 19 2018 15:45:13

The Apache HTTP Server Project has released “Apache HTTP Server 2.4.39” that addresses six vulnerabilities. This update fixes six vulnerabilities, including CVE-2019-0211, which may allow code execution with higher privileges.

In addition to “CVE-2019-0211”, “CVE-2019-0217” may be authenticated by another user in Digest authentication, and “CVE-2019-2015” may bypass access control by the client certificate. As for “,” the vulnerability is rated as “Important”, which is the second of four in the rating.

In addition, the three vulnerabilities with the lowest “Low” severity of vulnerability listed as “Low” fix “CVE-2019-0196”, “CVE-2019-0197”, “CVE-2019-0220” did.

なるほど、脆弱性に対応してるのね。