how to create new database user in mysql python

Step1

Set Mysql variable path

set path=%PATH%;C:\xampp\mysql\bin;

Step 2
Using command prompt login to databse

mysql -u root -p

Password NULL
create a database python

Step 3
Create new username and password
jack username
jackpassword is the password

c:\python>mysql -u root -p
Enter password: *
Welcome to the MariaDB monitor.  Commands end with ; or \g.
Your MariaDB connection id is 18
Server version: 10.1.34-MariaDB mariadb.org binary distribution

Copyright (c) 2000, 2018, Oracle, MariaDB Corporation Ab and others.

Type 'help;' or '\h' for help. Type '\c' to clear the current input statement.

MariaDB [(none)]> GRANT ALL PRIVILEGES ON *.* TO 'jack'@'localhost' IDENTIFIED BY 'jackpassword';
Query OK, 0 rows affected (0.00 sec)

MariaDB [(none)]>

Step 4
create new database using Python mysql connection

import mysql.connector

mydb = mysql.connector.connect(
  host="localhost",
  user="jack",
  passwd="jackpassword"
)

mycursor = mydb.cursor()

mycursor.execute("CREATE DATABASE myschool")

For Loop Syntax in Python

For Loop in Python

The for loop that is used is python,whenever we need repetition or iterate over a sequence .For Loop is one the frequently using loop in python.For loop has simple syntax .Let see the for loop syntax in details.

Here we are going to iterate over a sequence


#For Loop Syntax in Python

cars = ["SWIFT", "BELANO", "BMW"]
for x in cars:
  print(x) 

Output

SWIFT
BELANO
BMW

PHP sample code to create an authorisation key using JSON Web Tokens (JWT)

We know that API play an important role for connecting or transferring data between different system or application with the server,when we are dealing with customer data one of with biggest issue is the security.we need proper authorization to exchange data between the system. Fortunatily we have JSON Web Tokens(JWT) it helps us to create a authorization key and verify the authorization key. here we are checking out how to create a authorization key using JSON Web Tokens(JWT)in PHP.

Let we check in steps

Steps 1

Download JSON Web Tokens library from below link 
https://jwt.io/     download for PHP

Steps2

Create public key and private key


// Create the keypair
$res=openssl_pkey_new();

// Get private key
openssl_pkey_export($res, $privateKey);

// Get public key
$pubkey=openssl_pkey_get_details($res);
$publicKey=$pubkey["key"];

Step 3

Create a PHP page with below code to generate authorisation key


require_once PROJECT_ROOT.'/php-jwt/src/BeforeValidException.php';
require_once PROJECT_ROOT.'/php-jwt/src/ExpiredException.php';
require_once PROJECT_ROOT.'/php-jwt/src/SignatureInvalidException.php';
require_once PROJECT_ROOT.'/php-jwt/src/JWT.php';
use \Firebase\JWT\JWT;
$token_array=array();
$token_array['time']=time();
$token_array['user_name']="sachin";
$token_array['user_id']="144";
$token_array['mobile']="*********";
$token_array['admin']=false;
$authorisation_key=JWT::encode($token_array, $privateKey, 'RS256');

echo $authorisation_key;

Step 4

Create a PHP page with below code to verify authorisation key


require_once PROJECT_ROOT.'/php-jwt/src/BeforeValidException.php';
require_once PROJECT_ROOT.'/php-jwt/src/ExpiredException.php';
require_once PROJECT_ROOT.'/php-jwt/src/SignatureInvalidException.php';
require_once PROJECT_ROOT.'/php-jwt/src/JWT.php';
use \Firebase\JWT\JWT;
$token_array=array();
$token_array['time']=time();
$token_array['user_name']="sachin";
$token_array['user_id']="144";
$token_array['mobile']="*********";
$token_array['admin']=false;
$decoded = JWT::decode($token, $publicKey, array('RS256'));
print_r((array) $decoded);

How to insert new key value pair inside a multidimensional associative array in PHP

To insert new key value pair inside a multidimensional associative array in PHP
Here am going to explain in details
We have a sample array we need to add Version4 and its value inside the array

$list_array = array( 
            0 => array (
               "Version1" => 2016,
               "Version2" => 2017,	
               "Version3" => 2018
            ),
            
            1 => array (
               "Version1" => 2016,
               "Version2" => 2017,	
               "Version3" => 2018
            )
         );

Here am using for each mange that

 foreach($list_array as $key=>$valuue)
	 {
	  $list[$key]=$listvalue;
	  $list[$key]['Version4']= 2019;
	 }
       print_r($list);

Result

 
array( 
            0 => array (
               "Version1" => 2016,
               "Version2" => 2017,	
               "Version3" => 2018,
               "Version4" => 2019
          
              
            ),
            
            1 => array (
               "Version1" => 2016,
               "Version2" => 2017,	
               "Version3" => 2018,
               "Version4" => 2019
            )
         );