首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >不更新mySQL表的PHP

不更新mySQL表的PHP
EN

Stack Overflow用户
提问于 2016-07-26 05:50:18
回答 1查看 272关注 0票数 0

环境:

PHP7,mySQL,phpMyAdmin,localhost,MAMP,Mac

问题:

我正在将一些html文本解析到本地主机上的mySQL数据库中,并且字符串似乎没有按计划更新表。

我测试了代码,并将问题根缩小为包含在一个变量中的字符串,然后在mySQL表中更新该变量。

我测试了变量和查询语法,手动将变量中的字符串替换为‘tested’,并在运行代码时成功加载了该字符串。

我还尝试将mySQL表结构从“text”更改为“long text”,尽管字符串显然足够短,适合于文本字段,但这并没有帮助。

我非常确信问题在于字符串本身,可能还有表/字段结构。

还值得一提的是,查询更新通过这段代码与其他字符串一起工作,并且只在某些情况下失败(尽管经常失败)。

我想问的是

在这一点上,在尝试了一些事情和研究信息后,我有点卡住了问题可能是什么,所以任何建议都将是有用的,如果你曾经遇到过这个问题。下面是关于代码和字符串的更多信息。

信息

下面是字符串:

代码语言:javascript
复制
$Definition = verb (used without object) , abode or abided, abiding. 1. to remain; continue; stay: abide with me. 2. to have one's abode; dwell; reside: to abide in a small scottish village. 3. to continue in a particular condition, attitude, relationship, etc.; last. verb (used with object) , abode or abided, abiding. 4. to put up with; tolerate; stand: i can't abide dishonesty! 5. to endure, sustain, or withstand without yielding or submitting: to abide a vigorous onslaught. 6. to wait for; await: to abide the coming of the lord. 7. to accept without opposition or question: to abide the verdict of the judges. 8. to pay the price or penalty of; suffer for. verb phrases 9. abide by, to act in accord with. to submit to; agree to: to abide by the court's decision. to remain steadfast or faithful to; keep: if you make a promise, abide by it.;

代码:

代码语言:javascript
复制
        $Definition = implode('', $InterArray); //I also tested the array to string conversion works fine
        //$Definition = 'Test test test'; I tested this and it worked
        $Definition = (string) $Definition;

        $conn = mysqli_connect("localhost:8889","root","root","myDB");              
        $sql="INSERT INTO myTable (DEFINITION) VALUES('".$Definition."');";             
        $conn->query($sql);

SQL表:定义,类型:长文本,排序规则: latin_swedish_ci,默认值:无

EN

回答 1

Stack Overflow用户

回答已采纳

发布于 2016-07-26 05:57:34

为了避免任何混淆,最好使用mysqli_real_escape_string()而不是手动转义字符串。mysqli_real_escape_string()函数负责转义本身。

根据php.net

此函数用于创建可在SQL语句中使用的合法SQL字符串。给定的字符串被编码为转义的SQL字符串,同时考虑到连接的当前字符集。

正如马格努斯所说,准备好的陈述总是最好的选择。你永远不能太确定你的应用程序的安全性。

票数 -2
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/38581920

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档