php - 对于 MySQL TEXT 类型,我应该使用 PDO PARAM_LOB 还是 PARAM_STR?

标签 php mysql text pdo

对于 MySQL TEXT 类型,我应该使用 PDO PARAM_LOB 还是 PARAM_STR 吗?我预计我的数据将超过 5000 个字符。

$stmt->bindParam(':notes', $notes, PDO::PARAM_STR);

或者

$stmt->bindParam(':notes', $notes, PDO::PARAM_LOB);

最佳答案

如果您要使用大量数据,正如您在用例中提到的那样,那么是的 - 我会使用 PDO::PARAM_LOB 使用数据来操作您的数据流。

根据PHP documentation :

At some point in your application, you might find that you need to store "large" data in your database. Large typically means "around 4kb or more", although some databases can happily handle up to 32kb before data becomes "large". Large objects can be either textual or binary in nature. PDO allows you to work with this large data type by using the PDO::PARAM_LOB type code in your PDOStatement::bindParam() or PDOStatement::bindColumn() calls. PDO::PARAM_LOB tells PDO to map the data as a stream, so that you can manipulate it using the PHP Streams API.

像这样使用它:

<?php
$db = new PDO('odbc:SAMPLE', 'db2inst1', 'ibmdb2');
$stmt = $db->prepare("select contenttype, imagedata from images where id=?");
$stmt->execute(array($_GET['id']));
$stmt->bindColumn(1, $type, PDO::PARAM_STR, 256);
$stmt->bindColumn(2, $lob, PDO::PARAM_LOB);
$stmt->fetch(PDO::FETCH_BOUND);

header("Content-Type: $type");
fpassthru($lob);

关于php - 对于 MySQL TEXT 类型,我应该使用 PDO PARAM_LOB 还是 PARAM_STR?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/36724703/

相关文章:

PHP 和 mySQL 单引号还是双引号?

javascript - 当字符串位于注释中时,如何改进此正则表达式以使其不匹配

wpf 列表框将单个项目更改为粗体

php - 404 Not found - 为什么我不能在 laravel 中打开除 "/"之外的任何 View ?

mysql - 如何根据与特定纬度/经度的距离查询 Amazon Redshift 表中的用户 ID 列表?

c# - 如何将 PHP 函数的结果发送到 C# 客户端?

php - mySQL 没有获取所有记录

html - 显示多行文本的正确方法是什么?

php - PHP 大型上传的内存限制

php - MySQL通过php错误插入用户名和密码