MySQLI Vs PDO_MySQL Comparison

mysqli_vs_pdomsql

Currently recommended to use either the mysqli or PDO_MySQL extensions. It is not recommended to use the old mysql extension for new development, as it was deprecated in PHP 5.5.0 and was removed in PHP 7.

Features MySQLI Extention PDO_MySQL
PHP version introduced 5 5.1
Development status Active Active
Lifecycle Active Active
Recommended for new projects Yes Yes
OOP Interface Yes Yes
Procedural Interface Yes No
Persistent Connections Yes Yes
API supports Charsets Yes Yes
API supports server-side Prepared Statements Yes Yes
API supports client-side Prepared Statements No Yes
API supports Stored Procedures Yes Yes
API supports Multiple Statements Yes Yes
API supports Transactions Yes Yes
Transactions can be controlled with SQL Yes Yes
Supports all MySQL 5.1+ functionality Yes Mostly

More Information

Advertisements

InnoDB Storage Engine | MySQL Storage Engine

mysql_storage_engine_innodb

InnoDB is a high-reliability and high-performance storage engine

The InnoDB storage engine maintains its own buffer area for caching data and indexes in main memory. InnoDB stores its tables and indexes in a table-space, which may consist of several files (or raw disk partitions). This is different from when compared to MyISAM tables where each table is stored using separate files.

InnoDB Supports :

  • ACID Model (Atomicity,  Consistency, Isolation, and Durability)
    • Atomicity – Transaction Commits, when all the changes are succeed. Transaction Rollback, when all the changes are undone.
    • Consistency – The database remains in a consistent state at all times (before & after transactions)
    • Isolation – Transactions do not interfere with each others, when other transaction in progress.
    • Durability – InnoDB protect the data from crashes & any other danger. It can be achieve through double buffer.
  • Row-Level Locking
    • The system of protecting a transaction from seeing or changing data that is being queried or changed by other transactions.
  • Foreign Key
    • The foreign key relationship is defined on one column in both the parent table and the child table.
    • If a row is deleted or its foreign key value changed, and rows in another table point to that foreign key value, the foreign key can be set up to prevent the deletion, cause the corresponding column values in the other table to become null, or automatically delete the corresponding rows in the other table.
  • FULLTEXT index
    • The special kind of index that holds the search index in the MySQL full-text search mechanism. Represents the words from values of a column, omitting any that are specified as stopwords.
    • Available only @ MySQL 5.6.4 or Above

Printf Function in PHP

printf() Output Formatting

boolean printf (string format [, mixed args])

Printf() output a formatted string that specified in args, except that the output is formatted according to format.

printf( "I'm a %s", "Developer" ); // Developer

The % sign indicates that we are splicing some data into the string, and the s character indicates that we are splicing in a string. The part of the string that begins with % is called the format specifier. And the apostrophe (')  will use to display the different character. The argument consists below components.

  • Padding specifier – Control outcome string size.The default is a space character.
  • Precision specifier – Number of decimal digits, to display accepts only float type.
  • Alignment specifier – Controls the outcome result whether it should be right or left justified.
  • Width specifier – Minimum number of characters, to display.
  • Type specifier – Describe the argument will be cast.

Type Description :
%b   – Presented as a binary number.
%c   – Presented as a character corresponding to that ASCII value.
%d  – Presented as a signed decimal number.
%f   – Presented as a floating-point number,  Default to a precision of 6 decimal places.
%o  – Presented as an octal number.
%s  – Presented as a string.
%u  – Presented as an unsigned decimal number.
%x  – Presented as a lowercase hexadecimal number.
%X  – Presented as an uppercase hexadecimal number.

Padding Specifier :

printf("%.7s",'Programmer'); // Program (Control the output string characters)

Alignment specifier :

printf("%'#15s","Program");  // ########Program
printf("%'#-15s","Program"); // Program######## (Negative adds the padding to right (-))

Precision specifier:

printf("%.1f",450.00); // 450.0
printf("%.5f",450.00); // 450.00000

Width Specifier :

printf("%20s", "Programmer"); //  Programmer (The blank spaces go at the beginning, by default)

Type Specifier:

printf(" Integer Refers - Octal : %o, Binary : %b, Decimal : %d, Floating Points : %f, Hex decimal : %x " , 25,25,25,25,25);
 //Integer Refers - Octal : 31, Binary : 11001, Decimal : 25, Floating Points : 25.000000, Hex decimal : 19

PHP Configuration Directives

Handling PHP Configuration Directives

The php.ini file is PHP’s global configuration file, there are 12 different aspects of PHP behavior which includes:

• Language Options
• Safe Mode
• Syntax Highlighting
• Miscellaneous
• Resource Limits
• Error Handling and Logging
• Data Handling
• Paths and Directories
• File Uploads
• fopen Wrappers
• Dynamic Extensions
• Module Settings

The php.ini file is a simple text file, consisting solely of comments and parameter = key assignment pairs. ex.

;
;engine (On, Off)
;
engine = On

Lines beginning with a semicolon are comments; the parameter engine is assigned the value On.
Read More…

Continue reading

PHP Database Support Options

PHP’s Database Support Options

PHP Native support is offered for over 25 database products, including

  • MySQL
  • dBase
  • Empress
  • IBM DB2
  • FilePro
  • Adabas D
  • FrontBase
  • Hyperwave
  • PostgreSQL
  • Informix
  • Ingres
  • Interbase
  • mSQL
  • direct MS-SQL
  • Oracle
  • Velocis
  • Ovrimos
  • Solid
  • Sybase
  • Unix dbm

Also the Abstraction Layers Functions are available to access the Berkeley DB mode databases.

PHP 7.0.0 Features – Upcoming Version

PHP 7.0.0 Features

Upcoming PHP new version is PHP 7.0.0 team planned to release the version on Nov 12 2015, periodically they released beta versions of PHP 7.0.0.

PHP 7.0.0 comes with new version of the Zend Engine

  • Improved performance: PHP 7 is up to twice as fast as PHP 5.6
  • Consistent 64-bit support
  • Many fatal errors are now Exceptions
  • Removal of old and unsupported SAPIs and extensions
  • The null coalescing operator (??)
  • Combined comparison Operator (<=>)
  • Return Type Declarations
  • Scalar Type Declarations
  • Anonymous Classes

https://wiki.php.net/todo/php70#timetable (check the PHP 7.0.0 version release details)

Solution to improve your PHP Code

PHP - PracticesJust improve the readability, maintainability, and usability of your PHP code.

Use a functions

 To separate the code into individual functions.

Proper name for functions and variables

Give the exact and identifying names to your functions and variables

Avoid nested conditions

Instead of nested condition, try to use functions with return statement.

Use a PHP Built-in functions

Lets try with existing PHP functions, instead of writing your own code. Already lots of PHP Built-in function are available.

Search following URL http://php.net/manual/en/funcref.php