douying9296 2014-05-30 21:13
浏览 70
已采纳

PHP脚本可以发送到MySQL TEXT字段的最大数据量?

So I'm having the same problem as the folks here:

But I didn't see any genuine solutions to the problem besides the hack the guy posted in the first one to split the text up. The scripts have been tested and save to the database fine when it's a small amount of text, and the php script can save the largetext to a txt file fine as well. So the problem is somewhere on the Database side.

EDIT: The field I am posting to is already set to LONGTEXT

Here are my scripts:

post.php

<?php
$data=$_POST["SData"];  //Around 76kb of text 
$rName=$_POST["regName"];

include_once './db_functions.php';
$db = new DB_Functions();
$db->insertText($rName, $data);
?>

db_functions.php

//Insert Text Data into DB
public function insertText($regId, $sdata) {
    try {
        mysql_query("UPDATE users SET textdata = '$sdata' WHERE id = '$regId'");
    }
    catch (PDOException $e) {
        $output = 'Error performing update: ' . $e->getMessage();
    }

}

I have the following questions:

  1. What is the maximum datasize(amount of characters?) that I can send via PHP to a MySQL database? All the text i'm attempting to post is not necessary, so I could potentially limit it before I POST it. (But the more, the better)

  2. Is there an actual solution where I could send large datachunks over PHP?
    Potentially using 'the mysqli_stmt::send_long_data' found here: http://php.net/manual/en/mysqli-stmt.send-long-data.php ? Are there any examples of this being used that aren't just in the manual?

Any help would be greatly appreciated, thanks!!

  • 写回答

2条回答 默认 最新

  • duan19913 2014-05-30 22:07
    关注

    If you're using the obsolete mysql extension, you need to escape the data:

    $sdata = mysql_real_escape_string($_POST['SData']);
    

    It would be better to use PDO or mysqli and use prepared statements.

    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论
查看更多回答(1条)

报告相同问题?

悬赏问题

  • ¥15 关于大棚监测的pcb板设计
  • ¥20 sim800c模块 at指令及平台
  • ¥15 stm32开发clion时遇到的编译问题
  • ¥15 lna设计 源简并电感型共源放大器
  • ¥15 如何用Labview在myRIO上做LCD显示?(语言-开发语言)
  • ¥15 Vue3地图和异步函数使用
  • ¥15 C++ yoloV5改写遇到的问题
  • ¥20 win11修改中文用户名路径
  • ¥15 win2012磁盘空间不足,c盘正常,d盘无法写入
  • ¥15 用土力学知识进行土坡稳定性分析与挡土墙设计