Choosing an API

PHP offers different APIs to connect to MySQL. Below we show the APIs provided by the mysqli and PDO extensions. Each code snippet creates a connection to a MySQL server running on "example.com" using the username "user" and the password "password". And a query is run to greet the user.

Beispiel #1 Comparing the MySQL APIs

<?php
// 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']);

Feature comparison

The overall performance of both extensions is considered to be about the same. Although the performance of the extension contributes only a fraction of the total run time of a PHP web request. Often, the impact is as low as 0.1%.

  ext/mysqli PDO_MySQL
PHP version introduced 5.0 5.1
Included with PHP 7.x and 8.x Yes Yes
Development status Active Active
Lifecycle Active Active
Recommended for new projects Yes Yes
OOP Interface Yes Yes
Procedural Interface Yes No
API supports non-blocking, asynchronous queries with mysqlnd 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 Most
API supports Transactions Yes Yes
Transactions can be controlled with SQL Yes Yes
Supports all MySQL 5.1+ functionality Yes Most

Hier Kannst Du einen Kommentar verfassen


Bitte gib mindestens 10 Zeichen ein.
Wird geladen... Bitte warte.
* Pflichtangabe
Es sind noch keine Kommentare vorhanden.

Midjourney Tutorial - Anleitung für Anfänger

Über Midjourney, dem Tool zur Erstellung digitaler Bilder mithilfe von künstlicher Intelligenz, gibt es ein informatives Video mit dem Titel "Midjourney Tutorial auf Deutsch - Anleitung für Anfänger" ...

Mike94

Autor : Mike94
Kategorie: KI Tutorials

Grundlagen von Views in MySQL

Views in einer MySQL-Datenbank bieten die Möglichkeit, eine virtuelle Tabelle basierend auf dem Ergebnis einer SQL-Abfrage zu erstellen. ...

admin

Autor : admin
Kategorie: mySQL-Tutorials

Definition von Stored Procedures - eine Einführung

Stored Procedures sind vordefinierte SQL-Codeblöcke, die in einer Datenbank gespeichert sind und bei Bedarf aufgerufen werden können. ...

Bernie

Autor : ebiz-consult GmbH & Co. KG
Kategorie: mySQL-Tutorials

Tutorial veröffentlichen

Tutorial veröffentlichen

Teile Dein Wissen mit anderen Entwicklern weltweit

Du bist Profi in deinem Bereich und möchtest dein Wissen teilen, dann melde dich jetzt an und teile es mit unserer PHP-Community

mehr erfahren

Tutorial veröffentlichen

What defines Laravel's developer community?

Wenn Sie Ihr eigenes soziales Netzwerk erstellen möchten, empfehle ich Ihnen, den Blog zu lesen, in dem alles beschrieben ist https://merehead.co ...

Geschrieben von jord2 am 02.05.2024 13:44:45
Forum: PHP Developer Forum
Ich bin am verrückt werden - Session und neue Webseite

That is an extremely bright idea

Geschrieben von EssaMattou am 02.05.2024 09:34:57
Forum: SQL / Datenbanken
"Why adore HTMX over JavaScript?"

What specific features or aspects of HTMX, a library designed to enhance interactions in web applications, appeal to users who have a strong affin ...

Geschrieben von WartanThamar am 02.05.2024 06:53:08
Forum: HTML, JavaScript, AJAX, jQuery, CSS, Bootstrap, LESS