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 多电路系统共用电源的串扰问题
  • ¥15 slam rangenet++配置
  • ¥15 有没有研究水声通信方面的帮我改俩matlab代码
  • ¥15 对于相关问题的求解与代码
  • ¥15 ubuntu子系统密码忘记
  • ¥15 信号傅里叶变换在matlab上遇到的小问题请求帮助
  • ¥15 保护模式-系统加载-段寄存器
  • ¥15 电脑桌面设定一个区域禁止鼠标操作
  • ¥15 求NPF226060磁芯的详细资料
  • ¥15 使用R语言marginaleffects包进行边际效应图绘制