PHP中的MySQL与MySQLi [英] MySQL vs MySQLi in PHP

查看:69
本文介绍了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...)

推荐答案

您可以使用准备的语句使用mysqli.
还有一个用于存储大型(blob)数据的功能,旧的" mysql扩展名还没有.

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();

这篇关于PHP中的MySQL与MySQLi的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆