Back to all posts
MysqliPHPTechnology

Php Mysqli extension

SathishOctober 11, 2010
Php Mysqli extension

The MySql Improved Extension, a.k.a mysqli is faster more improved version of existing mysql. It is available in PHP 5 or later versions. The source code of mysqli is available at ext/mysqli.

Key Features of MySQLi

  • Object-oriented interface
  • Support for Prepared Statements
  • Support for Multiple Statements
  • Support for Transactions
  • Enhanced debugging capabilities
  • Embedded server support

Basic Connection Example

php
<?php
// Procedural style
$link = mysqli_connect("localhost", "user", "password", "database");

if (!$link) {
    die("Connection failed: " . mysqli_connect_error());
}

echo "Connected successfully";

// Object-oriented style
$mysqli = new mysqli("localhost", "user", "password", "database");

if ($mysqli->connect_error) {
    die("Connection failed: " . $mysqli->connect_error);
}

echo "Connected successfully";
?>

Prepared Statement Example

php
<?php
$mysqli = new mysqli("localhost", "user", "password", "database");

$stmt = $mysqli->prepare("INSERT INTO users (name, email) VALUES (?, ?)");
$stmt->bind_param("ss", $name, $email);

$name = "John";
$email = "[email protected]";
$stmt->execute();

echo "New record created successfully";

$stmt->close();
$mysqli->close();
?>

For further information on MySQLi, refer to the official PHP documentation.

0claps
Share this post

Comments

Protected by reCAPTCHA v3

No comments yet. Be the first to comment.