What is an API?
What is an API?
An Application Programming Interface, or API, characterizes the classes, strategies, capacities and factors that your application should bring so as to do its ideal undertaking. On account of PHP applications that need to speak with databases the essential APIs are normally uncovered by means of PHP augmentations.
APIs can be procedural or object-arranged. With a procedural API you get capacities to complete errands, with the article situated API you start up classes and afterward call strategies on the subsequent items. Of the two the last is generally the favored interface, as it is progressively current and prompts better sorted out code.
When composing PHP applications that need to interface with the MySQL server there are a few API alternatives accessible. This record examines what is accessible and how to choose the best answer for your application.
What is a Connector?
In the MySQL documentation, the term connector alludes to a bit of programming that enables your application to interface with the MySQL database server. MySQL gives connectors to an assortment of dialects, including PHP.
In the event that your PHP application needs to speak with a database server you should compose PHP code to perform such exercises as interfacing with the database server, questioning the database and other database-related capacities. Programming is required to give the API that your PHP application will utilize, and furthermore handle the correspondence between your application and the database server, perhaps utilizing other transitional libraries where essential. This product is referred to conventionally as a connector, as it enables your application to interface with a database server.
What is a Driver?
A driver is a bit of programming intended to speak with a particular sort of database server. The driver may likewise call a library, for example, the MySQL Client Library or the MySQL Native Driver. These libraries actualize the low-level convention used to speak with the MySQL database server.
By method for a model, the PHP Data Objects (PDO) database deliberation layer may utilize one of a few database-explicit drivers. One of the drivers it has accessible is the PDO MYSQL driver, which enables it to interface with the MySQL server.
Once in a while people utilize the terms connector and driver conversely, this can be befuddling. In the MySQL-related documentation the term driver is saved for programming that gives the database-explicit piece of a connector bundle.
What is an Extension?
In the PHP documentation you will run over another term – augmentation. The PHP code comprises of a center, with discretionary expansions profoundly usefulness. PHP’s MySQL-related expansions, for example, the mysqli augmentation, and the mysql augmentation, are actualized utilizing the PHP augmentation system.
An expansion commonly opens an API to the PHP developer, to enable its offices to be utilized automatically. Be that as it may, a few augmentations which utilize the PHP expansion structure don’t open an API to the PHP software engineer.
The PDO MySQL driver augmentation, for instance, doesn’t open an API to the PHP software engineer, however gives an interface to the PDO layer above it.
The terms API and expansion ought not be interpreted as meaning something very similar, as an augmentation may not really open an API to the software engineer.
What are the fundamental PHP API contributions for utilizing MySQL?
There are three fundamental API alternatives when considering interfacing with a MySQL database server:
o PHP’s MySQL Extension
o PHP’s mysqli Extension
o PHP Data Objects (PDO)
Every ha its own points of interest and disservices. The accompanying exchange plans to give a short prologue to the key parts of every apus.
What is PHP’s MySQL Extension?
This is the first augmentation intended to enable you to create PHP applications that cooperate with a MySQL database. The mysql augmentation gives a procedural interface and is proposed for utilize just with MySQL variants more seasoned than 4.1.3. This augmentation can be utilized with forms of MySQL 4.1.3 or more up to date, yet not the entirety of the most recent MySQL server highlights will be accessible.
What is PHP’s mysqli Extension?
The mysqli augmentation, or as it is at times known, the MySQL improved expansion, was created to exploit new highlights found in MySQL frameworks variants 4.1.3 and more up to date. The mysqli augmentation is incorporated with PHP renditions 5 and later.
The mysqli augmentation has various advantages, the key upgrades over the mysql expansion being:
o Object-situated interface
o Support for Prepared Statements
o Support for Multiple Statements
o Support for Transactions
o Enhanced investigating capacities
o Embedded server support
What is PDO?
o PHP Data Objects, or PDO, is a database reflection layer explicitly for PHP applications. PDO gives a reliable API to your PHP application paying little mind to the sort of database server your application will interface with. In principle, in the event that you are utilizing the PDO API, you could switch the database server you utilized, from express Firebird to MySQL, and just need to roll out minor improvements to your PHP code.
o Other instances of database reflection layers incorporate JDBC for Java applications and DBI for Perl.
o While PDO has its points of interest, for example, a perfect, straightforward, compact API, its fundamental drawback is that it doesn’t enable you to utilize the entirety of the propelled highlights that are accessible in the most recent forms of MySQL server. For instance, PDO doesn’t enable you to utilize MySQL’s help for Multiple Statements.
o PDO is actualized utilizing the PHP augmentation structure; its source code is situated in the index ext/pdo.
What is the PDO MYSQL driver?
o The PDO MYSQL driver isn’t an API all things considered, in any event from the PHP software engineer’s point of view. Truth be told the PDO MYSQL driver sits in the layer beneath PDO itself and gives MySQL-explicit usefulness. The software engineer despite everything calls the PDO API, however PDO utilizes the PDO MYSQL driver to complete correspondence with the MySQL server.
o The PDO MYSQL driver is one of a few accessible PDO drivers. Other PDO drivers accessible incorporate those for the Firebird and PostgreSQL database servers.
o The PDO MYSQL driver is executed utilizing the PHP expansion system. Its source code is situated in the index ext/pdo_mysql. It doesn’t open an API to the PHP software engineer.
o For additional data on the PDO MYSQL driver.
What is PHP’s MySQL Native Driver?
o In request to speak with the MySQL database server the mysql expansion, mysqli and the PDO MYSQL driver each utilization a low-level library that actualizes the necessary convention. Previously, the main accessible library was the MySQL Client Library, also called libmysqlclient.
o However, the interface introduced by libmysqlclient was not improved for correspondence with PHP applications, as libmysqlclient was initially planned in view of C applications. Thus the MySQL Native Driver, mysqlnd, was created as an option to libmysqlclient for PHP applications.
o The mysql expansion, the mysqli augmentation and the PDO MySQL driver can each be separately arranged to utilize either libmysqlclient or mysqlnd. As mysqlnd is structured explicitly to be used in the PHP framework it has various memory and speed improvements over libmysqlclient. You are unequivocally urged to exploit these upgrades.
o The MySQL Native Driver must be utilized with MySQL server variants 4.1.3 and later.
o The MySQL Native Driver is executed utilizing the PHP expansion structure. The source code is situated in ext/mysqlnd. It doesn’t open an API to the PHP software engineer.