CHARACTER_OCTET_LENGTH

CHARACTER_OCTET_LENGTH must be the same as CHARACTER_MAXIMUM_LENGTH except for multibyte character set.

mysql> select * from `information_schema`.`columns` where `table_schema` = “test”;
+—————+————–+————+————-+——————+—————-+————-+———–+————————–+————————+——————-+—————+——————–+——————–+—————–+————–+————+—————-+———————————+—————-+
| TABLE_CATALOG | TABLE_SCHEMA | TABLE_NAME | COLUMN_NAME | ORDINAL_POSITION | COLUMN_DEFAULT | IS_NULLABLE | DATA_TYPE | CHARACTER_MAXIMUM_LENGTH | CHARACTER_OCTET_LENGTH | NUMERIC_PRECISION | NUMERIC_SCALE | DATETIME_PRECISION | CHARACTER_SET_NAME | COLLATION_NAME | COLUMN_TYPE | COLUMN_KEY | EXTRA | PRIVILEGES | COLUMN_COMMENT |
+—————+————–+————+————-+——————+—————-+————-+———–+————————–+————————+——————-+—————+——————–+——————–+—————–+————–+————+—————-+———————————+—————-+
| def | test | items | item_id | 1 | NULL | NO | int | NULL | NULL | 10 | 0 | NULL | NULL | NULL | int(11) | PRI | auto_increment | select,insert,update,references | |
| def | test | items | name | 2 | NULL | YES | text | 65535 | 65535 | NULL | NULL | NULL | utf8 | utf8_general_ci | text | | | select,insert,update,references | |
| def | test | items | price | 3 | NULL | YES | int | NULL | NULL | 10 | 0 | NULL | NULL | NULL | int(11) | | | select,insert,update,references | |
| def | test | name | name | 1 | NULL | YES | varchar | 255 | 765 | NULL | NULL | NULL | utf8 | utf8_general_ci | varchar(255) | | | select,insert,update,references | |
| def | test | name | password | 2 | NULL | YES | varchar | 255 | 765 | NULL | NULL | NULL | utf8 | utf8_general_ci | varchar(255) | | | select,insert,update,references | |
| def | test | news | id | 1 | NULL | NO | int | NULL | NULL | 10 | 0 | NULL | NULL | NULL | int(11) | PRI | auto_increment | select,insert,update,references | |
| def | test | news | content | 2 | NULL | YES | varchar | 100 | 300 | NULL | NULL | NULL | utf8 | utf8_general_ci | varchar(100) | | | select,insert,update,references | |
| def | test | user | id | 1 | NULL | NO | int | NULL | NULL | 10 | 0 | NULL | NULL | NULL | int(11) | MUL | auto_increment | select,insert,update,references | |
| def | test | user | name | 2 | NULL | YES | varchar | 20 | 60 | NULL | NULL | NULL | utf8 | utf8_general_ci | varchar(20) | | | select,insert,update,references | |
+—————+————–+————+————-+——————+—————-+————-+———–+————————–+————————+——————-+—————+——————–+——————–+—————–+————–+————+—————-+———————————+—————-+
9 rows in set (0.15 sec)

なんじゃーこりゃーーー

Laravel cache clear command

Even after restarting Apache, sometimes has internal chaches that don’t reflect the updated program.

php artisan cache: clear
php artisan config: clear
php artisan route: clear
php artisan view clear

If you want to do autoloading and re-optimize, you want to recreate the cache entirely.

composer dump-autoload
php artisan clear-compiled
php artisan optimize
php artisan config:cache

When recreating a new key and completely invalidate the previous cache.

php artisan key:generate

zipからダウンロード

set_time_limit(0);

$zip_name = 'create_zip_'.date('Ymd').'.zip';
$zip_tmp_dir = dirname(__FILE__).'/tmp_zip/'; 

$zip_obj = new ZipArchive();

$result = $zip_obj -> open($zip_tmp_dir.$zip_name, ZIPARCHIVE::CREATE | ZIPARCHIVE::OVERWRITE);
if(!$result){
    echo 'error code : '.$result;
    exit();
}

$files[] = [
	'zip_path' => 'building.jpg',
	'file_path' =>  dirname(__FILE__)."/".'building.jpg'
];

foreach ($files as $file)
{
    //ファイルを追加する場合
    $zip_obj -> addFile($file['file_path'], $file['zip_path']);
}

$zip_obj -> addFromString('test.txt', 'test');
$zip_obj -> close();

header('Content-Type: application/force-download;');
header('Content-Length: '.filesize($zip_tmp_dir.$zip_name));
header('Content-Disposition: attachment; filename="'.$zip_name.'"');
readfile($zip_tmp_dir.$zip_name);

$files[] = [
	'zip_path' => ['building.jpg', 'monkey.jpg'],
	'file_path' =>  ['building.jpg', 'monkey.jpg']
];

foreach ($files as $file)
{
    //ファイルを追加する場合
    $zip_obj -> addFile( dirname(__FILE__)."/".$file['file_path'], $file['zip_path']);
}

[Sun Apr 7 16:33:50 2019] PHP Notice: Undefined index: /home/vagrant/local/app/test/file_path in /home/vagrant/local/app/test/index.php on line 24
[Sun Apr 7 16:33:50 2019] PHP Warning: ZipArchive::addFile() expects parameter 2 to be string, array given in /home/vagrant/local/app/test/index.php on line 24

うん、まー要するに配列で渡せば、zipで複数ダウンロードできるってわけね。
チェックボックスなら、POSTで対象ファイルを渡せばOK

phpのzip機能

Check if PHP has Zip extension

[vagrant@localhost test]$ php -m
[PHP Modules]
bz2
calendar
Core
ctype
curl
date
dom
exif
fileinfo
filter
ftp
gd
gettext
hash
iconv
intl
json
libxml
mbstring
mysqli
mysqlnd
openssl
pcntl
pcre
PDO
pdo_mysql
pdo_sqlite
Phar
readline
Reflection
session
SimpleXML
sockets
SPL
sqlite3
standard
tokenizer
wddx
xml
xmlreader
xmlwriter
xsl
zip
zlib

うん、ありますね。

phpでファイルダウンロード

$file_name = "building.jpg";
$file_path = dirname(__FILE__)."/".$file_name;

$download_file_name = "building.jpg";

header('Content-Type: application/force-download;');
header('Content-Length: '.filesize($file_path));
header('Content-Disposition: attachment; filename="'.$file_name.'"');

readfile($download_file_name);

特に問題なし

うーん、複数のファイルをDLしたいです。

Config::Simple

Config::Simple – 簡単な設定ファイルクラス

use Config::Simple;
Config::Simple->import_from(‘app.ini’, \%Config);
$cfg = new Config::Simple(‘app.ini’);
$user = $cfg->param(‘User’);
%Config = $cfg->vars();
$cfg->param(‘User’, ‘sherzodR’);
$cfg->param(‘Users’, [‘sherzodR’, ‘geek’, ‘merlyn’]);
$cfg->param(-block=>’last-access’, -value=>{‘time’=>time()});
$mysql = $cfg->param(-block=>’mysql’);
$cfg->save();

Perl Scalars

Perl has three basic data types: scalars, scalar arrays, and scalar associative arrays. In this context, scalar data refers to simple data such as numbers and strings. Also, as an essential element of programming, there is the concept of variables. Variables are “value containers” that are used to temporarily store various values.
In Perl, there are three variables, scalar variable, array, and associative array respectively, in the form corresponding to each data type, and the scalar variable is the most basic one among them, and stores numerical value and character string can do.
Scalar variable names can start with $ (dollar) + one alphabetic character, and can use numbers, alphabetic characters and underscores thereafter. Also, because it is cause sensitive, $ a and $ A, for example, are treated as different things.

OK
$abc123
$abc_123

NG
$123abc
$abc-123

mysqldumpでテーブルをバックアップ

command

$ mysqldump -u root -p db table --single-transaction > hoge.dump

test

mysql> use test;
Reading table information for completion of table and column names
You can turn off this feature to get a quicker startup with -A

Database changed
mysql> show tables;
+----------------+
| Tables_in_test |
+----------------+
| items          |
| name           |
| news           |
| user           |
+----------------+
4 rows in set (0.00 sec)

[vagrant@localhost ~]$ mysqldump –single-transaction -u root -p test items > /tmp/dump/items.sql
Enter password:

ほーーーーーーー

複数テーブルの場合
[vagrant@localhost ~]$ mysqldump –single-transaction -u root -p test items name > /tmp/dump/some.dump
Enter password:

テーブルを複数並べればいいだけ。

オプション
–skip-lock-tables
–lock-tablesオプションを無効にする。–optが–lock-tablesを有効にするので、それを打ち消す為に使用する。

なるほどーーーーーー

mysqldump

Use mysqldump command to backup / resotre MySQL database. The mysqldump command is included with MySQL installation.

Will explain two backup method.
1. How to back up only specific databases
2. How to back up all databases

To dump backup data from a specific MySQL database, use the following command:

$ mysqldump --single-transaction -u username -p DBname > output destination file name

やってみます。
mysql> mysqldump –single-transaction -u root -p test > /tmp/dump/test.dump
-> ;
ERROR 1064 (42000): You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near ‘mysqldump –single-transaction -u root -p test > /tmp/dump/test.dump’ at line 1

あれ?????? これ、mysqlにログインしなくていいのかな。
[vagrant@localhost ~]$ mysqldump –single-transaction -u root -p test > /tmp/dump/test.dump
Enter password:
[vagrant@localhost ~]$

ほう、そういうことか。。

次はテーブルのバックアップもやりたいね。

空チェックをして型チェック

nullかチェックをして、その後、型チェックを行う

$var = "2019/04/01";

if(empty($var)){
	echo "値を入力してください";
} else{
	if(preg_match("/^[a-zA-Z0-9]+$", $var)){
		echo "英数字で入力してください";
	} else {
		echo "合格";
	}
}

うむ、nullかどうかはオブジェクトにしたいですな。