Posts Tagged ‘database’

New Features in PHP 7

Wednesday, May 2nd, 2018

Programming language and the programmers all over the world experienced a new wave of change when PHP7 launched. This web-based application is compatible with mobile, enterprises solutions, and cloud platforms. However, there are a lot more to learn about this version to get comfortable while programming. It has got two new operators and many more exciting changes to ease the PHP lovers around the globe. Let’s dig out what are those to get a quality knowledge supplement.

Speed:

First and foremost thing that immediately gets noticed is its speed. PHP7 has an almost double speed of operation as that of PHP 5.6. Regarding consistency, it stands high as compared to its earlier versions. This means you will gain more proficiency than before as unwanted time lags will not be there.

Improved open source scripting:

PHP5 was using Zend Engine II at its heart, but PHP7 has got an upgraded version, Zend Engine III. It can significantly improve the performance level. As it has been written in C that interprets PHP, the functionality gets enhanced. It comes under the code name of PHPNG (Next Generation). This ensures that PHP7 is a must-try affair for every programmer around the globe.

Manual Variable declaration:

PHP 7, unlike its previous shades, enables you to specify your desired variable through its Type Declaration feature. It not only makes your code easy to read but also enables you to make small changes to variables without bringing any effect to the overall result. Earlier, this feature was not present and PHP was automatically setting up the variables. This changeover need not require you to declare data types as variables will still have them attached. However, you can make some radical changes. For instance, you can add a string to an integer, and it won’t result in any programming error.

For example,

Function abx(): array {

Return [ ];

}

Consider the example shown above. It defines array type of variable. With return type declaration used above, the function will return only the array. You can use this logic for other returns types such as int, float, and bool. Thus, being a weakly typed language, PHP7 can help you enhance the quality of the code.

Handling Fatal Errors:

A slight mistake from your side and your script may get into a fatal error. This is a common problem that every programmer experiences and previous PHP versions used to stop the script without involving the error handler. However, PHP 7 gives a little relief. An exception will be thrown instead of closing the entire script down.

Easy User-land CSPRNG:

It is nothing but an application space present outside the Kernel. Easy User-land CSPRNG can be covered by privilege separation. This API enables you to use PHP 7 with ease. It is reliable and is used to generate cryptographically secure pseudo-random numbers. No doubt, these random data were also present in the earlier versions, but none of them were as secured at this time. The importance of random numbers goes primarily while designing the program for generating frequently changing random passwords.

Introduction of two new operators:

If you’re upgrading to PHP7, then you will get to know about two new operators; Spaceship operator (<=>) or Combined comparison and Null Coalesce Operator. Let’s get to know about these operators in brief.

Spaceship operator (<=>) or Combined comparison

This one has got behavior similar to strcmp() or version_compare(), but the good thing is that all generic PHP values can get utilized through this new operator in combination with usual semantics like <, <=, ==, >=, >, etc. The comparison rules used is same as that of the previous semantics.

This spaceship operator has got simple usage funda. This operator “(expr) <=> (expr)” will fetch you a value ZERO if both operands are of same value. If the left side is greater than the right side, you will get ONE and -ONE for vice versa condition.

To understand about its behavior better, see how it returns results in case of the followings:

//integers

Echo 11 <=> 11; //0

//Floats

Echo 11.5 <=> 12.5; //-1

//Strings

Echo c <=> b; //1

Use usort() along with this operator to make the ordering easier.

Null Coalesce Operator 

“??” this is the symbol of Null Coalesce operator. If you want to assign a value to nullable or reference type files, this one can be your savior. If the operand is not null, the operator will return you left-hand operand, and if the reverse is the case, you will get right-hand operand in return.

In PHP7, without engaging this operator, if you are trying to assign a nullable value to a non-nullable one, you will get compile time error for sure. However, the use of “??” operator won’t let that happen.

See the below example for more clarity.

Int? a = null; //here a is a nullable value type

Int x = 0; //here a is a non-nullable value type

X = a;

You will get compile time error as below:

Cannot implicitly convert “int”; to “int.” An explicit conversion exists.

Anonymous class:

A new entry to PHP7 is “anonymous classes.” These classes have no name and can be defined simply with a keyword “new class.” The functionality goes in the similar line as that of an object of named class. They have internally generated names so, we need not define them again. They are useful for creating one-off objects.

For example, consider the below one;

Anonymous class_Image

Earlier, for creating a new class, it was required to override a property or method. That was extending the named class. However, with Anonymous class, your job will be easy for creating a simple one-off object.

Namespace:

If you want to encapsulate the items, then Namespace is what you will be looking for in PHP7. It can import a group of classes, functions, and constraints from the same namespace.

See this example below.

Before PHP7, you need to work as below:

Use xyz\abc\class Z

Use xyz\abc\class Y as newcode

After PHP7, you can work as below:

Use xyz\abc\ {class Z, class Y as newcode};

Here, we have highlighted the most important ones. However, there is a long list of the same. There are few technical advantages also. For instance, it is a commonly known fact that Linux is a more favorable playground for PHP rather than Windows and until now, it was running smoothly on 32-bit Windows, but the current version supports 64-bit windows as well. Therefore, with so much of changeovers, PHP7 can be quoted as one of the major release after PHP5 since 2004. Try to keep digging this new platform to gain maximum output with minimum input.

How to Get Database credentials using WP Admin

Friday, July 18th, 2014

So you forgot database credentials?? Need to know your phpmyadmin credentials or database credential?  And you are asking How to Get Database credentials using WP Admin? Don’t worry. Yes !! It is easy if your website runs under WordPress and you have access to wp-admin.

Lets start right ??

Login to WordPress Admin

First of all login to your wp-admin panel. It is really easy if you know the WordPress. If you don’t know how to login to WP Admin just type URL like http://www.yoursite.com/wp-admin

In most cases it will take you to admin login screen. If not just check with your technical persons or make sure you know the directory name where the WordPress is actually installed.

After successful login you will be taken to dashboard and it will look something like this

Now lets move on to the real part. !!!

Add All in One WP Security Plugin

Move to Plugins tab under your wp-admin dashboard. Plugins tab will be on the left side.

Now you will be able to see the list of already installed plugins list on your website. Now if you have not installed “C and Firewall” plugin, just click on “Add New” button as shown below.

Now just do a search by typing “all in one wp security and  firewall” and our required plugin will be on the top of the seach results. Just click on install and after install activate it.

Get wp-config.php file

Now that we have installed our required plugin !! You will see a new tab under Dashboard called “WP Security”. Click on that and move to “Settings” option tab. As you see in the below picture you will have some tabs available in this page and just click on “wp-config.php file” and there you will see an option as “Backup wp-config.php file”. Click on that button, it will download your WordPress site’s config file copy.

Oh yes!!! You are almost done. Now just open that downloaded file using any text editor. And you will find a line with your needed credentials!