Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

MySQL vs MySQLi in PHP [duplicate]

Tags:

php

mysql

mysqli

What are the differences/advantages of each? Disadvantages?

I'm not looking for coding preferences or subjective answers.

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

like image 399
Moshe Avatar asked Nov 29 '22 20:11

Moshe


1 Answers

You can use prepared statements with mysqli.
And there's also a function to store large (blob) data that the "old" mysql extension has not.

// 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();
like image 178
VolkerK Avatar answered Dec 10 '22 09:12

VolkerK