MySQL vs MySQLi in PHP

What are the differences / benefits of each? Disadvantages?

I am not looking for coding preferences or subjective answers.

What are the practical differences? (Storage, implementation, how the code looks, environment requirements ...)

+5
source share
3 answers

You can use prepared statements using mysqli.
In addition, there is a function for storing large (blob) data that the "old" mysql extension does not have.

// php-mysql: no oo-interface
$mysqli = new mysqli('localhost', 'localonly', 'localonly');
if ($mysqli->connect_error) {
  die($mysqli->connect_error);
}

// php-mysql: no prepared statements
$stmt = $mysqli->prepare("INSERT INTO foo (mydata) VALUES (?)");
$stmt->bind_param("b", $null);

// php-mysql: no function to send data in chunks
$fp = fopen("php://input", "r");
while (!feof($fp)) {
  $chunk = fread($fp, 4096);
  $stmt->send_long_data(0, $chunk);
}
$stmt->execute();
+11
source

overview PHP, .

+9

Prepared statements are available in mysqli for one. You can also use the OO interface, so instead mysql_foo_bar()you have one $con->foo_bar().

+3
source

All Articles