Posts

Showing posts from August, 2021

How To Use DB Queries In Laravel

How To Use DB Queries In Laravel - Laravel is PHP Framework for Web Application. It is a Free -> Open Source PHP Framework. It's follow the Standard Coding way MVC (Models, Views, Controllers) Concept. Model -> It mainly interact with the Database. Database Queries like Insert,Update,Select,Delete etc. Controller -> It's responsible for Users Action and Buisness Logic of the application. View -> It's most interacting part of the web application for Users. Now DB Queries - How to use in Laravel code 1.Check the columns in the database table for particular table query is -- $columns = DB::select( DB::raw('SHOW COLUMNS FROM TABLE_NAME')); 2. If you want to modify your database table DB::statement('ALTER TABLE TABLE_NAME MODIFY COLUMN_NAME DATATYPE NOT NULL'); DB::statement('ALTER TABLE User MODIFY user_id INT(20) NOT NULL'); 3. Get data for particular table form database DB::select('SELECT * FROM TABLE_NAME'

How To Show Emoji Stored In Database

How To Show Emoji Stored In Database - Emoji is Stored in Database Instead of showing ❤ Love 😋 Emoji's they are showing ????? Love ????? . So it's basically Database Charset and Collection Problem. So that's why we unable to get the Emojis on Front End. So we can use to Mysql Command for this. ALTER TABLE TABLENAME CONVERT TO CHARACTER SET utf8mb4 COLLATE utf8mb4_unicode_ci; ALTER TABLE TABLENAME MODIFY COULMNNAME TEXT CHARSET utf8mb4; In First Command we can Change the Charset and Collate for table and after that Second Command is use to modify the Column Where Emojis are stored. In Laravel we can use these commands. Don't forget to use Laravel DB class for Database Queries. DB::statement("ALTER TABLE TABLENAME CONVERT TO CHARACTER SET utf8mb4 COLLATE utf8mb4_unicode_ci"); DB::statement("ALTER TABLE TABLENAME MODIFY COULMNNAME TEXT CHARSET utf8mb4;"); or in PHP We can use mysqli_set_charset($connect, 'utf8mb4') $connect=mysql

How to Convert stdClass Object into Array for Data Transfer

How to Convert stdClass Object into Array for Data Transfer When ever you stuck with data transfer error that is stdClass Object with Object,String related Error . First of all Encode your Object Response with json_encode like json_encode($response) and after that Decode the Result with json_decode(json_encode($response), true); and get your response and use it.