mysql 查询等待,通过MySQL查询文本等待处理

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

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 :

stored url : http://site1.com|http://site2.com|....

search routine :

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

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

解决方案

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;

Edit: 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)."'");

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值