Blog

How to duplicate a MySQL table, including indexes and data?

There are MySQL GUI and tools that makes table duplication easy. But sometimes, you wish to copy table from CLI. This post is about doing it from CLI.

So, to copy everything, including database objects such as indexes, primary key constraint, foreign key constraints, triggers, etc., run these queries:

CREATE TABLE new_table LIKE old_table; // copies table structure and indices
 
INSERT new_table SELECT * FROM old_table; // copies data into new_table

https://tableplus.io/blog/2018/11/how-to-duplicate-a-table-in-mysql.html

Render Template without a custom Controller – Symfony

In any MVC framework when you want to show any page you would normally create a controller and render template from within the controller.

Laravel Framework

class BooksController extends Controller
{
    /**
     * @return \Illuminate\Contracts\View\Factory|\Illuminate\View\View
     */
    public function index()
    {
        $books = Book::all();
        return view('books.index', compact('books'));
    }
}

Symfony Framework

class BooksController extends AbstractController {

	/**
	 * @Route("/")
	 *
	 * @return Response
	 */
	public function index() {
             $books = $this->getDoctrine()->getRepository(Books::class);
             return $this->render("books/index.html.twig", [
			'books' => $liveAlarms,
			]
		);
       }
}

But in Symfony, if you are rendering a simple template, for instance, static content which doesn’t need any data from Controller you can still render it without creating a Controller by using built-in TemplateController.

# config/routes.yaml
acme_privacy:
    path:         /privacy
    controller:   Symfony\Bundle\FrameworkBundle\Controller\TemplateController
    defaults:
        template: static/privacy.html.twig
    methods: GET

Check if script is running in CLI

There may be number of occasions when you want to check if the script is running on Command Line Interface (CLI) or the browser an you may have come across various solutions that work on one occasion but not other.

I have come across one solution that would consider various factors to decide if it is running on CLI.

function is_cli()
{
    if ( defined('STDIN') )
    {
        return true;
    }

    if ( php_sapi_name() === 'cli' )
    {
        return true;
    }

    if ( array_key_exists('SHELL', $_ENV) ) {
        return true;
    }

    if ( empty($_SERVER['REMOTE_ADDR']) and !isset($_SERVER['HTTP_USER_AGENT']) and count($_SERVER['argv']) > 0) 
    {
        return true;
    } 

    if ( !array_key_exists('REQUEST_METHOD', $_SERVER) )
    {
        return true;
    }

    return false;
}

Virtualmin

Virtualmin is one of the popular opensource freely available cloud computing control panels for Web Hosting.

Virtualmin-Dashboard
Virtualmin-Dashboard

I have been looking for various control panels to host some websites I deal with on daily basis and I came across handful of some interesting control panels such as Plesk, CPanel etc to name a few. These are not free though, costing at least £9.16/month and $20/month respectively at the time of writing this post.

Recommended System Specifications

  • Automated installation requires a freshly installed, supported OS.
  • 1 GB RAM (less for the –minimal installation), more is better
  • 1 GB free disk space, more for your domain data

Mainden Post

Hello – welcome to my blog. Yes, this is the first post of the blog since the new site was setup. But don’t worry I will be posting new stuff soon on here. So keep looking at this space for some exciting stuff.

As you may already be aware that I am an experienced developer and currently working at Virgin Media. I have working with some interesting technology stack previously and therefore, I will be writing about them here in my blog.

State of the art technology stack is the key to any business’s success and being a developer my first priority is to keep myself updated about the latest trends in the market and implement them where appropriate. I am sure you will learn something as I keep writing about my experiences.

So stay tuned until then and I will be back with some brand new post soon.