Skip to main content

Posts

Showing posts from December, 2019

MYSQL Table Joining

leftJoin ==  LEFT OUTER JOIN join == innerjoin right join == RIGHT OUTER JOIN Print raw SQL queries for debugging $connection = \ Drupal :: service( ' database ' ); $query = $connection -> select( ' node ' , ' node ' ); $query -> fields( ' node ' , [ ' nid ' ]) -> condition( ' node.type ' , ' page ' ) // Debug. dump( $query -> __toString()); Which Table is in Left and whilch is in Right Lets suppose there are two tables, emp and deptt  SELECT emp.name,emp.no,d_name FROM emp left outer join deptt on (emp.dept_no = dept.dept_no) it left Join , and in left side table is emp and right side table is deptt. When we perform the left join it return the emp table. Type of Joins :  1  - Inner join (Natural join)(join)       1.1 - Natural join         1.2 - Conditional join or theta join        1.3 - Equi join 2 - Outer join:  ...

SQL Query Interview Questions

/* Return Employee record With highest Salary */ SELECT * from employee where salary = (SELECT Max(salary) from employee); /* Select highest salary in employee table */ SELECT Max(salary) from employee; /* Select 2nd highest salary from employee */ SELECT Max(salary) from employee where salary Not in (SELECT Max(salary) from employee) /* select Range of employee based on id */ SELECT * FROM  employee where employee_id between 2003 and 2008

Migration Part I : Drupal to Drupal migration

Drupal 8 core provides support for Drupal-to-Drupal migrations.  it will allow you to migrate your content from previous versions to Drupal 8. Core: Migrate Migrate Drupal Contributed: Migrate Upgrade (drupal.org/project/migrate_upgrade) Migrate Tools (drupal.org/project/migrate_tools) Migrate Plus (drupal.org/project/migrate_plus) Step 1 - goto your drupal 8 site setting.php and add the drupal 7 db setting in this file, so default drupal 8 db settings comes with  $database['default']['default']  copy this and make new key named as  $database['upgrade']['default'] like below $databases [ 'upgrade' ] [ 'default' ] = array ( 'database' = > 'dbname' , 'username' = > 'dbuser' , 'password' = > 'dbpass' , 'prefix' = > '' , 'host' = > 'localhost' , 'port' = > '3306' , 'n...

Composer With Drupal 8

Steps to install the d8 site with composer: 1 - composer create-project drupal/recommended-project drupal8-pattern --no-interaction 2 - Add the permission /sites/default/files -- 777 and then visit the project from the browser and install, Composer.json : To start using Composer in your project, all you need is a composer.json file. This file describes the dependencies of your project and may contain other metadata as well. Installing dependencies : php composer.phar install When you run this command, one of two things may happen: with composer.lock or without composer.lock Installing without composer.lock If you have never run the command before and there is also no composer.lock file present, Composer simply resolves all dependencies listed in your composer.json file and downloads the latest version of their files into the vendor directory in your project. (The vendor directory is the conventional location for all third-party c...

OOPS in PHP part II

Final Class & Method: method:: The final keyword  allows you to mark methods so that an inheriting class can not overload them. class myclass final function getbaseclassname(){ return _class_; } After declaring a class as final ,it can't inherited. The  final  keyword is used to prevent a class from being inherited and to prevent inherited method from being overridden. Class Constants : Class constants can be useful if you need to define some constant data within a class. A class constant is declared inside a class with the  const  keyword. We can access a constant from outside the class by scope resolution operator(::). class   Goodbye {    const  LEAVING_MESSAGE =  "Thank you for visiting W3Schools.com!" ; } echo   Goodbye::LEAVING_MESSAGE; Or, we can access a constant from inside the class by using the  self  keyword followeed by resolution, like self::LEAVING_MESSAGE PHP 8.1 F...

Dependency Injection in Drupal 8

Here are the important nuggets: DI is a design pattern used in programming. DI uses composition. DI achieves inversion of control. Dependency == service that your class needs == object of a certain type. Inject == provide == compose == assemble. Container == service container == dependency container. Instead of using  \Drupal::service('foo_service') , get the service from the  $container  if using a class. And the important reasons: Externalizing dependencies makes code easier to test. It allows dependencies to be replaced without interfering with other functionality. Retrieving dependencies from the container is better for performance. Services: node.grant_storage The easiest examples to find are services that have arguments, because you can search *.services.yml files for the word "arguments". In  node.services.yml  for example, there is this entry: node.grant_storage: class: Drupal\node\NodeGrantDatabaseStorage argument...

Mysql Interview Questions

Current mysql version : 8 ( last was 5.7 ,  5.7 to directly 8 ) SHOW FULL PROCESSLIST is used to see all the query executing when refresh the site. 1 second == 1000 mili second, 0-500 ms responce time of any query is ok How to Read the MySQL Slow Query Log :   The MySQL slow query log is where the MySQL database server registers all queries that exceed a given threshold of execution time. This can often be a good starting place to see which queries are slowest and how often they are slow. MySQL on your server is configured to log all queries taking longer than 0.1 seconds. /var/log/mysql/mysql-slow.log Use EXPLAIN or EXPLAIN EXTENDED to explain the query how it is executed. MySQL  describe  or  ANALYZE  command shows the structure of the table. Best practice in respect of performance : 1 - always use index, 2 - index types , primary index and combined field index like fname & lname in one index not two index, 3 - one index sc...