Useful PHP Sample Coding Website Links

http://thisinterestsme.com

https://www.geeksforgeeks.org/

https://codesays.com/solutions-to-training-by-codility/

http://a4academics.com/interview-questions/53-database-and-sql/397-top-100-database-sql-interview-questions-and-answers-examples-queries?showall=&limitstart=

Advertisements

Syntax error or access violation: 1071 Specified key was too long; max key length is 767 bytes (SQL: alter table `users` add unique `u sers_email_unique`(`email`))

Got error message while running “php artisan migrate” at laravel 5.7

Solution

For laravel 5.7
This solution solve my problem
go to config/database.php
Find the code below

‘mysql’ => [
‘driver’ => ‘mysql’,
‘host’ => env(‘DB_HOST’, ‘127.0.0.1’),
‘port’ => env(‘DB_PORT’, ‘3306’),
‘database’ => env(‘DB_DATABASE’, ‘forge’),
‘username’ => env(‘DB_USERNAME’, ‘forge’),
‘password’ => env(‘DB_PASSWORD’, ”),
‘unix_socket’ => env(‘DB_SOCKET’, ”),
‘charset’ => ‘utf8mb4’,
‘collation’ => ‘utf8mb4_unicode_ci’,
‘prefix’ => ”,
‘strict’ => true,
‘engine’ => null,
],
Change this two field

‘charset’ => ‘utf8mb4’,
‘collation’ => ‘utf8mb4_unicode_ci’

With This

‘charset’ => ‘utf8’,
‘collation’ => ‘utf8_unicode_ci’

Cheers

How to install Node.js via binary archive on Linux (node-v8.11.3-linux-x64.tar.xz)

1) Node version = node-v8.11.3-linux-x64.tar.xz
Unzip the binary archive to any directory you wanna install Node, I use /usr/local/lib/nodejs

VERSION=v8.11.3
DISTRO=linux-x64
sudo mkdir /usr/local/lib/nodejs
sudo tar -xJvf node-v8.11.3-linux-x64.tar.xz -C /usr/local/lib/nodejs
sudo mv /usr/local/lib/nodejs/node-v8.11.3-linux-x64 /usr/local/lib/nodejs

2) Set the environment variable sudo nano ~/.profile, add below to the end

# Nodejs
export NODEJS_HOME=/usr/local/lib/nodejs/node-v8.11.3-linux-x64/bin
export PATH=$NODEJS_HOME:$PATH

3) Refresh profile
. ~/.profile
( . is including within command )

4) Test installation using
$ node -v

How to deploy Laravel Project at CPanel without installing Composer

How to deploy Laravel Project at CPanel without installing Composer

1) Generate – Compile the whole project at local and add one php file to run php scripts at Server
/project_name/public/to_compile_again.php

<?php
system(‘php ../artisan config:clear’);
system(‘php ../artisan config:cache’);
system(‘php ../artisan cache:clear’);
system(‘php ../artisan config:cache’);
?>

2) Upload the whole project to the server at CPanel
3) Create a new subdomain
4) Run the subdomain from the browser
5) Compile the whole project from Browser
eg
http://test.aceinspirationtest.webstarterz.com/to_compile_again.php

5) Run the subdomain / configured domain from browser

Myanmar Font in TC/PDF export in PHP with laravel

You need to download the font ttf file
Zawgyi-One-20051130.ttf

================
Utility.php
=================
<?php namespace App\Core;

use Validator;
use Auth;
use DB;
use App\Http\Requests;
use App\Session;
use PDF;
use TCPDF_FONTS;

class Utility
{
// Use Pdf Export
public static function exportPDF($html,$pdfTitle = 'exportPDF')
{
PDF::SetTitle($pdfTitle);

require_once(base_path() . '/vendor/tecnickcom/tcpdf/include/tcpdf_fonts.php');
// $pdf = new TCPDF(PDF_PAGE_ORIENTATION, PDF_UNIT, PDF_PAGE_FORMAT, true, 'UTF-8', false);
$fontname = TCPDF_FONTS::addTTFfont(app_path() .'/Core/Export/Zawgyi-One-20051130.ttf', 'TrueTypeUnicode', '', 32);

// $font1 = PDF::addTTFfont('/home/waiyan/Downloads/Zawgyi-One-20051130.ttf', 'TrueTypeUnicode', '', 8);
PDF::SetFont($fontname, '', 15, '', false);

// set font
//PDF::SetFont('helvetica', '', 12);
PDF::AddPage();
PDF::writeHTML($html, true, false, false, false, '');

PDF::Output($pdfTitle . '.pdf');
exit();

}

}
===========================================
ServicePdfGenerator.php
===========================================
<?php

namespace App\Core\Export;

use Illuminate\Support\Facades\DB;
use Illuminate\Support\Facades\Input;
use App\Core\Config\Config;
use App\Core\Utility;
use PDF;

class ServicePdfGenerator implements IPDFGeneratorInterface
{
public function generate($paramObj)
{

ob_end_clean();
ob_start();

$html = <<<EOD

.table_main {
font-size: 10;
}

.table_border {
border: 1;
}

ကခဂ ကခဂ ကခဂ ကခဂ

EOD;

Utility::exportPDF($html,”mm_font_pdf”);
return true;

}
}
==============================================

dompdf/dompdf v0.7.0 requires ext-gd * -> the requested PHP extension gd is missing from your system

Problem 1
    - dompdf/dompdf v0.7.0 requires ext-gd * -> the requested PHP extension gd is missing from your system.
    - barryvdh/laravel-dompdf v0.7.0 requires dompdf/dompdf ^0.7 -> satisfiable by dompdf/dompdf[v0.7.0].
    - Installation request for barryvdh/laravel-dompdf ^0.7.0 -> satisfiable by barryvdh/laravel-dompdf[v0.7.0].


Solution

If you are working in PHP version 5.* then you have to install

sudo apt-get install php5-gd
And if you are working in PHP version 7.* then you have to install

sudo apt-get install php7.0-gd

Hope it will work..

Cheers