php - mysql_real_escape_string 在 php 5.4.44 中不起作用

标签 php mysql mysql-real-escape-string php-5.4

我在我的网站上运行 PHP 版本 5.4.44 并尝试使用 mysql_real_escape_string 但它没有给我任何东西。mysql_real_escape_string 在我的计算机上的 localhost 中工作得很好。示例代码

 <?php
    echo 'What is Your Name='.mysql_real_escape_string("my name is ");
    ?> 

输出

What is Your Name=

最佳答案

mysql_real_escape_string

mysql_real_escape_string — Escapes special characters in a string for use in an SQL statement

在向 MySQL 发送查询之前,必须始终使用此函数(除了少数异常(exception))以确保数据安全。

所以在使用mysql_real_escape_string之前需要创建数据库连接

$link = mysql_connect('mysql_host', 'mysql_user', 'mysql_password')
    OR die(mysql_error());

   echo 'What is Your Name='.mysql_real_escape_string("my name is ");

输出

What is Your Name=my name is

已更新

根据我们的讨论,您正在使用 mysqli,因此您在代码中混合了 mysql 和 mysqli

mysqli_real_escape_string($con,("my name is 'kk/'");//pass first parameter your database connection

关于php - mysql_real_escape_string 在 php 5.4.44 中不起作用,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/33429863/

相关文章:

php - 自动更改记录

mysql - Ruby Mysql2 客户端在插入时不带反斜杠

php - 防止在没有事件数据库连接的情况下使用 mysql_real_escape_string 时出现错误

php - 单击提交按钮后按 f5

javascript - HTML 表单在提交时触发 php 和 javascript

javascript - Ajax 数据类型 : JSON respond is: OK but No output?

mysql - 连接到局域网中另一台PC上的mysql服务器

php - 我的 pdo 登录功能需要帮助

mysql - 如何在 Codeigniter 中绑定(bind)使用 LIMIT 参数变量的查询

php - MySql mysql_real_escape_string 错误