Magento Engineer
social
Mysql

Mysql

The industry's top wizards and other experts share their advice and research findings.

How to Move Your Blog/Website from WordPress.com to WordPress.org?

Many beginners often start with WordPress.com, but they soon realize its limitations and want to switch to the self-hosted WordPress.org platform.

In this step by step guide, we’ll show you how to properly move your blog from WordPress.com to WordPress.org.

Step1 - Login in the wordpress.com admin.
Step2 - Check "All-in-One WP Migration" from left sidebar and if it is not availble in your website then ping to  WordPress.com support team to add this.

Step3 - Open All-in-One WP Migration and click on export.

Step4 - Here you will see multiple export options, now choose FILE.
Step5 - Download will be started.

Step6 - The exported file will be in "wpress" format.
Step7 - Now run below command to extract and you will get Database and all wordpress files including plugin,theme,uploads.
Command: npx wpress-extract migration.wpress

Step8- Change wp-config.php and URL's from database and upload on new server.

That's it.
:) Enjoy

Ad comes here
Ad comes here

What is differences between PHP5 and PHP7 ?

Main differences between PHP5 and PHP7 are as below -

1. PHP 5 is using Zend Engine II while PHP7 is using PHPNG (that is PHP Next Generation)
2. Benchmarks for PHP 7 consistently show speeds twice as fast as PHP 5.6
3. In PHP7, error exception facility called Engine Exception is present in which you can mark the fatal error as exception
4. PHP7 supports 64-bit system while PHP5 does not support it
5. PHP7 introduced New Operators

Ad comes here

Basic & Advanced MySQL Interview Questions with Answers

MySQL Questions with Answers

Question : How can we know the total number of elements of Array?
Answer :
sizeof($array_var)
count($array_var)
If we just pass a simple var instead of a an array it will return 1.

Question : Different Types of Tables in Mysql?
Answer : There are Five Types Tables in Mysql
1)INNODB
2)MYISAM
3)MERGE
4)HEAP
5)ISAM

Question : What is the difference between the functions unlink and unset?
Answer :
unlink() deletes the given file from the file system.
unset() makes a variable undefined.

Question : In how many ways we can retrieve the data in the result set of MySQL using PHP?
Answer : You can do it by 4 Ways
1. mysql_fetch_row.
2. mysql_fetch_array
3. mysql_fetch_object
4. mysql_fetch_assoc


Question : What do DDL, DML, and DCL stand for?
Answer : DDL is the abbreviation for Data Definition Language dealing with database schemas as well as the description of how data resides in the database. An example is CREATE TABLE command. DML denotes Data Manipulation Language such as SELECT, INSERT etc. DCL stands for Data Control Language and includes commands like GRANT, REVOKE etc.

Question : What are the different types of strings in Database columns in MySQL?
Answer : Different types of strings that can be used for database columns are SET, BLOB, VARCHAR, TEX, ENUM, and CHAR.

Question : Is there an object oriented version of MySQL library functions?
Answer : MySQLi is the object oriented version of MySQL and it interfaces in PHP.

Question : How to display Nth highest salary from a table in a MySQL query?
Answer : Let us take a table named employee.

To find Nth highest salary is:
select distinct(salary) from employee order by salary desc limit n-1,1  

If you want to find 3rd largest salary:
select distinct(salary) from employee order by salary desc limit 2,1

Question : What is the difference between mysql_connect and mysql_pconnect?
Answer : Mysql_connect() is used to open a new connection to the database while mysql_pconnect() is used to open a persistent connection to the database. It specifies that each time the page is loaded mysql_pconnect() does not open the database.

Question : How many TRIGGERS are possible in MySql
Answer : Six triggers are possible to use in MySQL database .
1.Before Insert
2.After Insert
3.Before Update
4.After Update
5.Before Delete
6.After Delete

Question : How to delete only the repeated records from a USER table ?
Answer : First we need to select only those records which are repeated giving a constraint :count should be greater than one to make the signle record deletion work. Suppose repeating of record is considered by column name.

SELECT * FROM(SELECT id FROM user GROUP BY name HAVING COUNT(*) > 1) AS A

Then will apply the deletion on those records.
DELETE FROM user WHERE id IN(SELECT * FROM(SELECT id FROM user GROUP BY name HAVING COUNT(*) > 1) AS A)

Ad comes here

How to get all posts from the specific / single category of custom post types in Wordpress ?

<div class="custom-post-entry">
    <?php query_posts( 'post_type=story&category_name=winner'); ?>       
    <?php if ( have_posts() ) while ( have_posts() ) : the_post(); ?>  
    <?php //get_template_part( 'content', 'page' ); ?>
    <?php get_template_part( 'content', get_post_format() ); ?>
    <?php comments_template( '', true ); ?>
    <div class="clear"></div>
</div><!--post-entry end-->
<?php endwhile; ?>

Ad comes here
Ad comes here
Ad comes here

How to run custom MySql query in Magento2 and fetch data?

<?php

//Connection with magento2 database

$objectManager = \Magento\Framework\App\ObjectManager::getInstance();
$resource = $objectManager->get('Magento\Framework\App\ResourceConnection');
$connection = $resource->getConnection('core_read');

//Now execute your mysql query

$fetch="SELECT * FROM catalog_product_entity";

$result = $connection->fetchAll($fetch);

?>

Ad comes here

How do you Encrypt and Decrypt a PHP String?

/**Function to encrypt or decrypt the given value**/
/**Create a function for Encryption url**/

function encrypt_decrypt($string){   
    $string_length=strlen($string);
    $encrypted_string="";     
    for ($position = 0;$position<$string_length;$position++){         
        $key = (($string_length+$position)+1);
        $key = (255+$key) % 255;
        $get_char_to_be_encrypted = SUBSTR($string, $position, 1);
        $ascii_char = ORD($get_char_to_be_encrypted);
        $xored_char = $ascii_char ^ $key;  //xor operation
        $encrypted_char = CHR($xored_char);
        $encrypted_string .= $encrypted_char;
    }
    /***Return the encrypted/decrypted string***/
    return $encrypted_string;
 }

/*** While passing the unique value to a link- Do the following steps ***/
$pid=88;//Let's 88 is the actual id
/***For more security multiply some value-You can set the multiplication value in config file*/
$passstring=$pid*12345;
$encrypted_string=encrypt_decrypt($passstring);
$param=urlencode($encrypted_string);

/*** Add this url to your anchor link***/
$url='your_target_path.php?id='.$param;
 
/*** While fetching the params in the target file- Do the following steps ***/
$getid=$_GET['id'];
$passstring=urldecode(stripslashes($getid));
$decrypted_string= encrypt_decrypt($passstring);
/***Divide the decrypted value with the same value we used for the multiplication***/
$your_actual_id= $decrypted_string/12345;

/*** Now fire your MySql query by this ID***/

Ad comes here

How to validate Alpha Numeric password validation ?

Must contain at least one number and one uppercase and lowercase letter and one special charectar, and at least 8 or more characters.

Method First:

<form action="#">
Password: <input type="password" name="password" id="password"
pattern="(?=.*?[A-Z])(?=.*?[a-z])(?=.*?[0-9])(?=.*?[^\w\s]).{8,}"
title="Must contain at least one number and one uppercase and lowercase letter and one special charectar, and at least 8 or more characters">
<input type="submit">
</form>

Method second through PHP validation :

$uppercase = preg_match('@[A-Z]@', $password); //uppercase
$lowercase = preg_match('@[a-z]@', $password); //lowercase
$number    = preg_match('@[0-9]@', $password); //numbers
$special   = preg_match('@[!@#$%^&*/()\-_=+{};:,<.>]@', $password); //special charectar

if(!$uppercase || !$lowercase || !$number || !$special || strlen($password) < 8) {
// tell the user something went wrong
}

Ad comes here

How to write databse query in mysql,pdo and mysqli format?

Databse query in mysql,pdo and mysqli format.

MySQL = Popular open source relational database management system.
MySQLi - Improved PHP MySQL extension Read here
PDO - PHP extension similar to MySQLi. Provides object oriented way to access database

MySqli

$mysqli =new mysqli("example.com","user","password","database"); 
$result = $mysqli->query("SELECT 'Hello, dear MySQL user!' AS _message FROM DUAL");
$row = $result->fetch_assoc(); echo htmlentities($row['_message']);

PDO

$pdo =new PDO('mysql:host=example.com;dbname=database','user','password'); 
$statement = $pdo->query("SELECT 'Hello, dear MySQL user!' AS _message FROM DUAL");
$row = $statement->fetch(PDO::FETCH_ASSOC); echo htmlentities($row['_message']);

MySQL

$c = mysql_connect("example.com","user","password"); 
mysql_select_db("database");
$result = mysql_query("SELECT 'Hello, dear MySQL user!' AS _message FROM DUAL");
$row = mysql_fetch_assoc($result); echo htmlentities($row['_message']);

Ad comes here

Upwork Test Answers | WordPress Upwork Test Answers 2017

Upwork Test Answers | WordPress Upwork Test Answers 2017

Q1.) select all the default taxonomies in wordpress.
Ans.)
1)category
2) post_tag
3) link_category
4) post_category
5) post_format
Q2.) which concept does wordpress uses to control user access to different features.
Ans.) Role
Q3.) Which of the following is a not default image size in WP?
Ans.) Small size
Q4.) What is the name of table in database which stores custom fields data?
Ans.) wp_postmeta
Q.5) What are WordPress hooks?
Ans.) group of plugins which control wordpress behavior
Q6.) How do you enable the network setup menu item(enable multisite) in wordpress?
Ans.) set WP_Allow_MULTISITE as true in wp_config.php
Q7.) how to style each list item background of the wordpress navigation separately.
Ans.)
    nav li:nth-child(1).current-menu-item
    {
    background-color: red;
    }
    nav li:nth-child(2).current-menu-item
    {
    background-color: blue;
    }
    nav li:nth-child(3).current-menu-item
    {
    background-color: green;
    }
Q8.)If you need to store information temporarily, which wordpress system would you use :
Ans.) Transients
Q9.) how do you enable debug mode in WP?
Ans.) By setting WP_DEBUG as true in WP-Config.php
Q10.) what can the contributer role do?
Ans.) Edit Posts
Q11.)Which constant is NOT recognized in wp-config.php?
Ans.) wp_HOME_URL
Q12.)Which wp global object is used to execute custom databse queries?
Ans.) $wpdb
Q13.)Which one of the following files is located in the root of your wordpress installation directory and contains your website’s setup details, such as database connection info?
Ans.)wp_config.php
Q14.)what is user Management?
Ans.) WP User Manager. Managing your members, creating front-end profiles and custom login and registration pages should be easy. You easily add custom userregistration, login and password recovery forms to your WordPress website.
Q15.) How you can create a static page with wordpress?
Ans.) to create a static page in wordpress………
Q16.) Is it possible to create posts programmatically?
Ans.) Yes,with wp_insert_post() function
Q17.) which of the following is the correct way to register shortcode?
Ans.)
function foobar_func( $atts )
{
return “foo and bar”;
}
add_shortcode( ‘foobar’, ‘foobar_func’ );
Q18.) What is wordpress multisite?
Ans.) wp configuration features that supports multiple sites.
Q19.) Which of the following is not a default user role in wp?
Ans.) Blogger
Q20.) What does wp_rand() function?
Ans.) Generates a random number.
Q21.) Which of the following is not a wordpress role?
Ans.) System
Q22.) Which of the following is incorrect possible value for $show attribute of bloginfo($show) function?
Ans.) ‘homeurl’
Q23.) pick the correct default post types readily available to users or internally used by the wordpress installation.
Ans.)
1) post
2) page
Q24.) what is common to all these functions: next_post,previous_post,link_pages,the _author_url,wp_get_link?
Ans.) They are all deprecated.
Q25.)Wordpress navigation menu without sub menu.
Ans.) wp_nav_menu( array( ‘theme_location’ => ‘primary’, ‘menu_class’ => ‘nav-menu’,’depth’ => 1) ) );
Q26.)Which of the following post types are by default available in wordpress installation(choose all the apply)
Ans.) Post
Page
Q27.) What is the difference between the wp_title and the_title tags?
Ans.) wp_title() function is for use outside “The Loop” to display the title of a page. the_title() on the other hand is used within “The Loop”.
Q28.)Which of the following HTML tags are not allowed to be used in a post comment?
Ans.) Form
Img
Q29.) A wordpress___________ is a collection of files that work together produce a graphical interface with an underlying unifying design for a weblog.
Ans.) Theme
Q30.) Themes typically reside in the ______________ directory.
Ans.) wp-content/themes
Q31.) _________________ is the ability for readers to respond to articles writte in your blog.
Ans.) Comment Posting
Q32.) A/an __________ is a globally recognized avatar.
Ans.) gravatar
Q33.) _______________ make it possible for a person to have one avatar across              the entire web.
Ans.) Gravatar
<
Q34.) where are plugin options stored in WordPress ?.
Ans.) They are stored in WordPress plugin folder
Q35.) What is the default site update service that WordPress automatically notifies when you publish a new post?
Ans.) http://rpc.pingomatic.com
Q36.)  Pick the default template tag(s).
Ans.) wp_title
the_title
Q37.) WordPress uses a ____________ in conjucntion with the mod_rewrite       Apache module to produce permalinks?
Ans.) an .htaccess file
Q38.) What is permalink?
Ans.) The complete url of your wordpress site.
Q39.)Where can you change the Timezone used by WordPress in the dashboard?
Ans.)In Settings > General
Q40.) _____________ are condensed summaries of your blog posts.
Ans.) Excerpts
Q41.) What database does WordPress use?
Ans.) MySQL
Q42.)In manual installation,wp-config-sample.php shoud be renamed to_____.
Ans.) wp-config.php
Q43.) What is the default table prefix in WP?
Ans.) wp_

Ad comes here
Error's and solution's
Update Cookies Preferences