Dual procedural and object-oriented interfaceThe mysqli extension features a dual interface. It supports the procedural and object-oriented programming paradigm. Users migrating from the old mysql extension may prefer the procedural interface. The procedural interface is similar to that of the old mysql extension. In many cases, the function names differ only by prefix. Some mysqli functions take a connection handle as their first argument, whereas matching functions in the old mysql interface take it as an optional last argument.
Example #1 Easy migration from the old mysql extension
<?php The above example will output: Please, do not use the mysql extension for new developments. The object-oriented interface In addition to the classical procedural interface, users can choose to use the object-oriented interface. The documentation is organized using the object-oriented interface. The object-oriented interface shows functions grouped by their purpose, making it easier to get started. The reference section gives examples for both syntax variants. There are no significant performance differences between the two interfaces. Users can base their choice on personal preference.
Example #2 Object-oriented and procedural interface
<?php The above example will output: A world full of choices to please everybody. The object oriented interface is used for the quickstart because the reference section is organized that way. Mixing styles It is possible to switch between styles at any time. Mixing both styles is not recommended for code clarity and coding style reasons.
Example #3 Bad coding style
<?php The above example will output: Possible but bad style. See also
|