Posts

SOLID Principles

SOLID  is an acronym for the first five object-oriented design (OOD) principles SOLID stands for: S - Single-responsibility Principle O - Open-closed Principle L - Liskov Substitution Principle I - Interface Segregation Principle D - Dependency Inversion Principle

Explain MySQL Index & its type ?

Indexes are used to find rows with specific column values quickly. Without an index, MySQL must begin with the first row and then read through the entire table to find the relevant rows.  Five Types of Indexes When you create an index or add one to an existing table, you’ll create it as one of several types of indexes. A unique index is one in which all column values must be unique. In a single column unique index there can be no duplication of values in the column being indexed. In a multi-column unique index the values can be duplicated in a single column, but the combination of column values in each row must be unique. You use a unique index to prevent duplicate values and you often define the index after a table has been created. A primary key is a unique index in which no value can be NULL. Every row must have a value for the column or combination of columns. You would usually define a primary key on the smallest number of columns possible because of this, and most of the time a

Object oriented programming concepts in PHP

Is it always necessary to create objects from class? No. An object is necessary to be created if the base class has non-static methods. But if the class has static methods, then objects don’t need to be created. You can call the class method directly in this case, using the class name. How much memory does a class occupy? Classes do not consume any memory. They are just a blueprint based on which objects are created. Now when objects are created, they actually initialize the class members and methods and therefore consume memory. Can you create an instance of an abstract class? No. Instances of an abstract class cannot be created because it does not have a complete implementation. However, instances of subclass inheriting the abstract class can be created. What is a final variable? A variable whose value does not change. It always refers to the same object by the property of non-transversity. What are the differences between error and exception? Exception - Exception can be recovered b

When we can use abstract class & interface? Why we are using abstract class & interface?

  When to use Abstract Class? An abstract class is a good choice if we are using the inheritance concept since it provides a common base class implementation to derived classes. An abstract class is also good if we want to declare non-public members.  In an interface, all methods must be public. If we want to add new methods in the future, then an abstract class is a better choice. Because if we add new methods to an interface, then all of the classes that already implemented that interface will have to be changed to implement the new methods. When to use interface? If the functionality we are creating will be useful across a wide range of disparate objects, use an interface. Abstract classes should be used primarily for objects that are closely related, whereas interfaces are best suited for providing a common functionality to unrelated classes. Interfaces are a good choice when we think that the API will not change for a while. Interfaces are also good when we want to have something

MySQL query asked in interviews?

Concat two columns in SELECT query - SELECT employeeid, CONCAT(firstname, lastname) AS employee_name FROM employee; Concat by adding space -> CONCAT(firstname, ' ', lastname) AS employee_name Write a query to find even records in MYSQL.   SELECT * FROM EMPLOYEE WHERE id IN(SELECT id FROM EMPLOYEE WHERE id%2 = 0); Write a query to find odd records in MYSQL. SELECT * FROM EMPLOYEE WHERE id IN(SELECT id FROM EMPLOYEE WHERE id%2 <> 0); Get duplicate records from table SELECT name, count(name) FROM employee GROUP BY name HAVING(name) > 1 Get 4th Highest salary with limit function and without using limit functions SELECT name,email from users ORDER BY DESC LIMIT 4,1 Finding the highest salary select MAX(Salary) from Employee; Finding the 2nd highest salary Query-1 SELECT MAX(Salary) FROM Employee WHERE Salary NOT IN (SELECT MAX(Salary) FROM Employee); Query-2 select MAX(Salary) from Employee WHERE Salary <> (select MAX(Salary) from Employee ) Finding the nth highest

What are the main differences between INNODB and MYISAM?

Here are a few of the major differences between InnoDB and MyISAM: InnoDB has row-level locking. MyISAM only has full table-level locking. InnoDB has what is called referential integrity which involves supporting foreign keys (RDBMS) and relationship constraints, MyISAM does not (DMBS). InnoDB supports transactions, which means you can commit and roll back. MyISAM does not. InnoDB is more reliable as it uses transactional logs for auto recovery. MyISAM does not.

Why we use innodb as Engine in MySQL?

InnoDB is a storage engine in MySQL. InnoDB's greatest strengths are: Its design follows the ACID model, with transactions featuring commit, rollback, and crash recovery capabilities to protect user data. Row-level locking (without escalation to coarser granularity locks) and Oracle-style consistent reads increase multi-user concurrency and performance. Foreign key constraints. Allowing you to let the database ensure the integrity of the state of the database, and the relationships between tables. InnoDB tables arrange your data on disk to optimize common queries based on primary keys. Each InnoDB table has a primary key index called the clustered index that organizes the data to minimize I/O for primary key lookups. You can freely mix InnoDB tables with tables from other MySQL storage engines, even within the same statement. For example, you can use a join operation to combine data from InnoDB and MEMORY tables in a single query. InnoDB Limitations : No full-text indexing (Below-

How does request life cycle work in Laravel?

The entry point for all requests to a Laravel application is the public/index.php file. All requests are directed to this file by your web server (Apache / Nginx) configuration. The index.php file doesn't contain much code it's just starting point for loading the rest of the framework. The index.php file loads the Composer generated autoloader definition and then retrieves an instance of the Laravel application from bootstrap/app.php script. The first action taken by Laravel itself is to create an instance of the application/service container. HTTP / Console Kernels Next, the incoming request is sent to either the HTTP kernel or the console kernel, depending on the type of request that is entering the application. These two kernels serve as the central location that all requests flow through. For now, let's just focus on the HTTP kernel, which is located in the app/Http/Kernel.php. The HTTP kernel extends the Illuminate\Foundation\Http\ Kernel class, which defines an array

What is normalization in DBMS?

 Normalization is the technique of organizing the data into multiple tables to minimize data redundancy. Data redundancy means the reputation of data at multiple places. Different issues can be observed while insertion, Updation, Deletion. Unnecessary data reputation will increase the size of the database and leads to more issues. Normalization will break the table into two different tables.

How can we optimize database query?

MySQL is one of the most popular open-source Relational Database Management System (RDBMS) that uses Structured Query Language (SQL). Useful tips to improve MySQL Query for speed and performance. 1. Optimize Your Database You need to know how to design schemas to support efficient queries. Well-designed queries and schema are crucial for your application to work properly. Optimizing your MySQL queries alone will not bring excellent database performance. A well-structured database is crucial along with an optimized query. The following steps will help you to optimize your database. a. Normalize Tables b. Use Optimal Data Types c. Avoid Null Values d. Avoid Too Many Columns 2. Optimize Joins 3. Index All Columns Used in ‘where’, ‘order by’, and ‘group by’ Clauses 4. Use Full-Text Searches - MySQL full-text search (FTS) is far faster than queries using wildcard characters. To add a full-text search index to the students’ sample table, we can use the below MySQL command: mysql>Alter tab