AmitDiwan has Published 10744 Articles

Encrypt and Decrypt a string in MySQL?

AmitDiwan

AmitDiwan

Updated on 20-Nov-2020 07:18:17

7K+ Views

To encrypt and decrypt in MySQL, use the AES_ENCRYPT() and AES_DECRYPT() in MySQL −insert into yourTableName values(AES_ENCRYPT(yourValue, yourSecretKey)); select cast(AES_DECRYPT(yourColumnName, yourSecretKey) as char) from yourTableName;To understand the above syntax, let us first create a table −mysql> create table demo63 −> ( −> value blob −> ); Query OK, 0 ... Read More

How to add a row to a table using only strings from another table as reference in MySQL?

AmitDiwan

AmitDiwan

Updated on 20-Nov-2020 07:16:20

213 Views

For this, use INSERT INTO SELECT statement in MySQL. Let us create a table −mysql> create table demo61 −> ( −> id int, −> name varchar(20) −> ) −> ; Query OK, 0 rows affected (1.84 sec)Insert some records into the table with the help of insert command −mysql> insert ... Read More

SELECT WHERE IN null in MySQL?

AmitDiwan

AmitDiwan

Updated on 20-Nov-2020 07:14:04

527 Views

Following is the syntax −select yourColumnName1, yourColumnName2, yourColumnName3, . . . N from yourTableName where yourValue in(yourColumnName1, yourColumnName2) or yourColumnName1 is NULL;Let us create a table −mysql> create table demo60 −> ( −> id int not null auto_increment primary key, −> first_name varchar(20), −> last_name varchar(20) −> ) −> ; ... Read More

Change value of decimal(19, 2) when inserting into the database in MySQL?

AmitDiwan

AmitDiwan

Updated on 20-Nov-2020 07:10:41

203 Views

To store the exact real value, you need to use truncate() with 2 decimal point. Let us create a table −Following is the query to create a table.mysql> create table demo59 −> ( −> price decimal(19, 2) −> ); Query OK, 0 rows affected (1.12 sec)Insert some records into the ... Read More

Expression in CASE WHEN Clause doesn't work in MySQL query?

AmitDiwan

AmitDiwan

Updated on 20-Nov-2020 07:09:22

284 Views

Fir this, use CASE WHEN statement in MySQL correctly. Let us see how.Let us create a table −mysql> create table demo58 −> ( −> id int not null auto_increment primary key, −> first_name varchar(20), −> last_name varchar(20) −> ); Query OK, 0 rows affected (2.15 sec)Insert some records into the ... Read More

How to sort a particular value at the end in MySQL?

AmitDiwan

AmitDiwan

Updated on 20-Nov-2020 07:06:57

136 Views

For this, you can use ORDER BY. Let us create a table −mysql> create table demo57 −> ( −> id int not null auto_increment primary key, −> full_name varchar(20) −> ); Query OK, 0 rows affected (1.60 sec)Insert some records into the table with the help of insert command −mysql> ... Read More

Multiple data input at the same time in MySQL?

AmitDiwan

AmitDiwan

Updated on 20-Nov-2020 07:05:18

823 Views

Following is the syntax −insert into yourTableName values(yourValue1, yourValue2, .....N), (yourValue1, yourValue2, .....N), (yourValue1, yourValue2, .....N), (yourValue1, yourValue2, .....N), . . . NLet us create a table −mysql> create table demo56 −> ( −> id int, −> first_name varchar(20), −> last_name varchar(20), −> age int −> ); Query OK, 0 ... Read More

Update data in one table from data in another table in MySQL?

AmitDiwan

AmitDiwan

Updated on 20-Nov-2020 07:03:10

1K+ Views

For this, you can use UPDATE command along with JOIN.Let us create the first table −mysql> create table demo54 −> ( −> firstName varchar(20), −> lastName varchar(20) −> ); Query OK, 0 rows affected (0.57 sec)Insert some records into the table with the help of insert command −mysql> insert into ... Read More

PHP Pushing values into an associative array?

AmitDiwan

AmitDiwan

Updated on 20-Nov-2020 05:38:42

2K+ Views

To push values into an associative array, use the brackets [] []. At first create an associative array −$details= array (    'id' => '101',    'name' => 'John Smith',    'countryName' => 'US' );The PHP code is as follows to insert values −Example Live Demo OutputArray (  [studentDetails] => Array (     [0] => Array (        [id] => 101 [name] => John Smith [countryName] => US       )    ) )

Extract numbers after the last hyphen in PHP?

AmitDiwan

AmitDiwan

Updated on 20-Nov-2020 05:36:38

846 Views

Let’s say the following is our string including hyphen and numbers as well −"John-45-98-78-7898906756"To extract numbers after – i.e. hyphen, use the concept of explode() with parameters - and $yourVariableName.The PHP code is as follows −Example Live Demo Output7898906756

Advertisements