4

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...)

skaffman
  • 398,947
  • 96
  • 818
  • 769
Moshe
  • 57,511
  • 78
  • 272
  • 425

3 Answers3

11

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();
VolkerK
  • 95,432
  • 20
  • 163
  • 226
  • +1, Bonus Question - How would I set up MySQLi if I have MySQL installed? Can use MySQLi functions to call MySQL databases? – Moshe Dec 29 '09 at 02:37
  • You can use both modules to connect to a MySQL server. mysqli is "only" a php module that you can either compile into the php core or load as a module. e.g. *nix distributions often have php-modulename packages you can install through the ditribution's package manager. – VolkerK Dec 29 '09 at 03:15
9

Read the overview on the PHP manual, it answers most questions and has a comparison chart.

Pekka
  • 442,112
  • 142
  • 972
  • 1,088
  • From that overview: "If you are using MySQL versions 4.1.3 or later it is strongly recommended that you use the mysqli extension instead." – Oscar Oct 26 '12 at 04:10
3

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

Alex Budovski
  • 17,947
  • 6
  • 53
  • 58