PHPackages                             noahheck/e\_mysqli - PHPackages - PHPackages  [Skip to content](#main-content)[PHPackages](/)[Directory](/)[Categories](/categories)[Trending](/trending)[Leaderboard](/leaderboard)[Changelog](/changelog)[Analyze](/analyze)[Collections](/collections)[Log in](/login)[Sign up](/register)

1. [Directory](/)
2. /
3. [Database &amp; ORM](/categories/database)
4. /
5. noahheck/e\_mysqli

ActiveLibrary[Database &amp; ORM](/categories/database)

noahheck/e\_mysqli
==================

Replacement for default Mysqli class to allow viewing a parameterized query with the arguments inserted into the string

2.1.1(8y ago)101755[1 issues](https://github.com/noahheck/E_mysqli/issues)[2 PRs](https://github.com/noahheck/E_mysqli/pulls)Apache-2.0PHPPHP &gt;=5.6.0

Since Nov 7Pushed 3y ago7 watchersCompare

[ Source](https://github.com/noahheck/E_mysqli)[ Packagist](https://packagist.org/packages/noahheck/e_mysqli)[ Docs](https://github.com/noahheck/E_mysqli)[ RSS](/packages/noahheck-e-mysqli/feed)WikiDiscussions master Synced 2mo ago

READMEChangelog (4)Dependencies (3)Versions (7)Used By (0)

E\_mysqli
=========

[](#e_mysqli)

Replacement for default Mysqli class to allow viewing a parameterized query with the arguments inserted into the string

View the [changelog](CHANGELOG.md)

Usage
-----

[](#usage)

Provides similar functionality to that found in the PDO sister project:

[E\_PDOStatement](https://github.com/noahheck/E_PDOStatement)

Not being able to view a complete version of the query to be executed on the server after statement parameters have been interpolated can be frustrating.

**EMysqli** aims to ease this burden by providing developers the ability to view what would be an example of the query executed on the server:

```
$query 		= "INSERT INTO registration SET name = ?, email = ?";
$stmt 		= $mysqli->prepare($query);

$name 		= $_POST['name'];
$email 		= $_POST['email'];

$stmt->bind_param("ss", $name, $email);

$stmt->execute();

echo $stmt->fullQuery;
```

The result of this will be:

```
INSERT INTO registration SET name = 'John Doe', email = 'john.doe@example.com'
```

When used correctly, the interpolated values are escaped appropriately according to character set in use on the database server:

```
INSERT INTO registration SET name = 'Sue O\'Reilly', email = 'sue.o@example.com'
```

It's also possible to view the interpolated query string without executing the query:

```
$query 		= "INSERT INTO registration SET name = ?, email = ?";
$stmt 		= $mysqli->prepare($query);

$name 		= $_POST['name'];
$email 		= $_POST['email'];

$stmt->bind_param("ss", $name, $email);

$fullQuery 	= $stmt->interpolateQuery();// INSERT INTO registration SET name = 'John Doe', email = 'john.doe@example.com'
```

Further Enhancements
--------------------

[](#further-enhancements)

A (fortunate ?) side effect of the way **EMysqli** performs it's work also allows you to bind multiple parameters individually, helpful if your query string is generated in separate method/function calls.

This is accomplished by binding the parameters individually:

```
$name 		= $_POST['name'];
$email 		= $_POST['email'];

$stmt->bind_param("s", $name);
$stmt->bind_param("s", $email);
```

#### Note

[](#note)

Using either of these two methods stores the bound parameters as references to their runtime variables preventing the need to rebind parameters, which is the default method for handling bound parameters in mysqli:

```
$name 		= "John Doe";
$email 		= "john.doe@example.com";

$stmt->bindParam("s", $name);
$stmt->bindParam("s", $email);

$stmt->execute(); // INSERT INTO registration SET name = 'John Doe', email = 'john.doe@example.com'

$name 		= "Sue O'Reilly";
$email 		= "sue.o@example.com";

$stmt->execute(); // INSERT INTO registration SET name = 'Sue O\'Reilly', email = 'sue.o@example.com'
```

Installation
------------

[](#installation)

Install via composer:

```
composer require noahheck/e_mysqli

```

Configuration
-------------

[](#configuration)

**E\_mysqli** extends both the `mysqli` and `mysqli_stmt` classes. Your `mysqli` object creation process will simply need to be updated to generate an instance of `EMysqli\EMysqli` instead:

```
