通过MySQL查询文本等待处理 [英] Text proccessing via Mysql Query

查看:181
本文介绍了通过MySQL查询文本等待处理的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我必须为搜索和更新,它的解决方案是更好的性能被保存在数据库URL的很多的:

I have lot's of URL that must be saved in DB for searching and updating , which solution is better for performance :

1店网址中包含一列,并在以后的从数据库获取字符串,并将其爆炸到一个数组中,并使用 array_search 函数找到一个表字符串网址:

1-store url as string in a table that contain one column , and in later get string from db and explode them to an array and use array_search function to find a URL :

存储网址: HTTP://site1.com | HTTP://site2.com | ....

搜索程序:

$is_unique= array_search("$url" ,explode($row['url'] , "|"));

在db表2插入每每个URL一行,并使用查询搜索和更新。

2-insert one row per each URL in db table and use query for search and update.

推荐答案

让MySQL的处理搜索。 MySQL的可以利用索引,array_search不能。只是一定要对您的网址列声明的索引。你可以用下面的SQL语句创建一个索引:

Let MySQL handle searching. MySQL can make use of indexes, array_search cannot. Just be sure to declare an index on your url column. You can create an index with the following SQL statement:

CREATE INDEX url_index ON your_table_name (url);

如果您批量更新您的网址,你可以用你的更新在一个事务中,这使得它更快,因为该指数将在提交重新生成,而不是在每一个更新语句。

If you bulk update your urls, you can wrap your updates in a transaction, which makes it faster, because the index will be re-generated on commit, not on every single update statement.

START TRANSACTION;
[...your update statements go here...]
COMMIT;

编辑:关于安全性,因为我已经在你的说法中有一种看到它。如果用户提供的参数,你想用来逃避你输入mysql_real_escape_string()

About security, because I have seen it in one of your comments. If a parameter is user supplied, you want to escape your inputs with mysql_real_escape_string():

mysql_query("SELECT * FROM table WHERE url = ('".mysql_real_escape_string($your_url)."'");

有关安全性的详细信息,请参阅 PHP手册关于mysql_real_escape_string()和/或 google一下SQL注入

For details about security, please read the PHP manual about mysql_real_escape_string() and/or google about SQL injection

这篇关于通过MySQL查询文本等待处理的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆