Give User Access Specific Database (MySQL)

Ok first we need to create user, login user as root to your MySQL

> CREATE USER 'newuser'@'localhost' IDENTIFIED BY 'password';

after create user, create database then give privileges to the user

> CREATE DATABASE new_database;
> GRANT ALL PRIVILEGES ON new_database.* TO 'newuser'@'localhost';

then flush privileges

> FLUSH PRIVILEGES;

OK DONE.

source: https://www.digitalocean.com/community/tutorials/how-to-create-a-new-user-and-grant-permissions-in-mysql

Advertisements

Can’t Write/Access Directory – Centos 7

type this command into your shell

# SELinux serve files off Apache, resursive
sudo chcon -t httpd_sys_content_t /data/www/html/sites/mysite -R
 
# Allow write only to specific dirs
sudo chcon -t httpd_sys_rw_content_t /data/www/html/sites/mysite/logs -R
sudo chcon -t httpd_sys_rw_content_t /data/www/html/sites/mysite/uploads -R

source: https://blog.lysender.com/2015/07/centos-7-selinux-php-apache-cannot-writeaccess-file-no-matter-what/

thx.

Zip PDF File Into One (PHP)

function create_zip($files = array(),$destination = '',$overwrite = false) {
    if(file_exists($destination) && !$overwrite) { return false; }
    $valid_files = array();
    if(is_array($files)) {
        foreach($files as $file) {
            if(file_exists($file)) {
                $valid_files[] = $file;
            }
        }
    }
    if(count($valid_files)) {
        $zip = new ZipArchive();
        if($zip->open($destination,$overwrite ? ZIPARCHIVE::OVERWRITE : ZIPARCHIVE::CREATE) !== true) {
            return false;
        }
        foreach($valid_files as $file) {
            $zip->addFile($file,$file);
        }
        $zip->close();
        return file_exists($destination);
    }
    else
    {
        return false;
    }
}

$dir = 'file/';
$a = scandir($dir);
$searchForName = 'FI160009';
$files_to_zip = array();
foreach ($a as $key => $v) {
    if (strpos($v, $searchForName) !== false) {
        $files_to_zip[] = $dir.'/'.$v;
    } 
}

$result = create_zip($files_to_zip,$searchForName.'.zip', true);

then check on your directory. done

Generate Color For Row Array (Specific Colour Grouping)

create two below function

function random_color_part() {
	return str_pad( dechex( mt_rand( 0, 255 ) ), 2, '0', STR_PAD_LEFT);
}

function random_color() {
	$color =  $this->random_color_part() . $this->random_color_part() . $this->random_color_part();
	return $color;
}

then result set data

$res = SELECT FROM DB GROUP BY

foreach ($res as $key => $value) {
	$setcolor[trim($value['kelas'])] = $this->random_color();
}

foreach($loopingall as $v){
// check if any kelas value in color (group select)
if (in_array($v['kelas'], array_keys($setcolor))) {
	$color = $setcolor[$v['kelas']];
} else {
	$color = 'FFFFFF';
}

}

done dude.

ref: stackoverflow