我通过向具有函数的url发送请求来在MySQL中存储文本。
url以%20编码为空格,但是当它存储在MySQL中时,空格被替换为下划线_。
这是一个句子 - > This_is_a_sentence。
有没有办法避免这个问题?
这是代码:
function new_experiment_reply($thread_title = '', $raven_thread_id = '', $text = '', $forum_url = '', $raven_forum_id = '')
{
$email = $this->session->userdata('email');
$query = $this->db->query("SELECT id FROM fn_users WHERE email='" . $email . "'");
$fn_user_id = $query->first_row()->id;
$query = $this->db->query("SELECT username FROM forum_users WHERE fn_user_id='" . $fn_user_id . "' AND raven_forum_id='" . $raven_forum_id . "'");
$username = $query->first_row()->username;
$date = date("Y-m-d H:i");
$query = $this->db->query('INSERT INTO promo_replies(thread_title, raven_thread_id, text, forum_url, raven_forum_id, date, fn_user_id, username) VALUES("'. $thread_title .'", "'. $raven_thread_id .'", "'. $text .'", "'. $forum_url . '", "'. $raven_forum_id . '", "'. $date . '", "'. $fn_user_id . '", "'. $username . '") ');
}
变量的插入值(在Fiddler中看到它们应该是这样的):
$thread_title= Facebook%20vs%20Google
$raven_thread_id = 123441
$text = This%20is%20a%20sentence
$forum_url = domain.com
$raven_forum_id = 32
在回显查询后,我得到了以下结果:
INSERT INTO promo_replies
(thread_title, raven_thread_id, text, forum_url, raven_forum_id, date, fn_user_id, username)
VALUES
("Facebook_vs_Google", "123441", "This_is_a_sentence", "domain_com", "32", "2012-09-06 06:04", "8", "usssaa")
我准备对代码感到羞愧,所以不用担心。