SQL查询与PHP中的条件 [英] SQL Queries vs Conditions in PHP

查看:105
本文介绍了SQL查询与PHP中的条件的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

如果我们有一个大约1000-2000个元素的数组,并且mysql表大约1000-2000(可以增加)。我们必须找到表格内容是否在数组中。

If we are having an array of about 1000-2000 elements, and a mysql table of about 1000-2000 (can increase). We have to find that table content is in array or not.

哪种方法更好?


  1. 从数组中获取元素并运行简单的mysql查询,如 SELECT * ...... WHERE ..... (运行1-2k sql查询)

  2. 获取存储在其他数组中的mysql中的表,并用其他数据检查它的元素。即嵌套的for-loop类型。 (运行1个sql查询,然后运行1-2k条件检查)

  1. Getting an element from array and run simple mysql query like SELECT *...... WHERE..... (Running 1-2k sql queries)
  2. Get the table stored in mysql in other array and check it's element with other. i.e. nested for-loop type. (Running 1 sql query and then 1-2k condition checks)


推荐答案

使用html抓取数据与内置的dom解析器DOMDocument和DOMXPath相比,简单的dom解析器很慢。

scraping data with html simple dom parser is slow, as compared with the built-in dom parser DOMDocument and DOMXPath.

使用1000多个元素搜索大型php数组会比查询更慢db。

searching large php arrays with 1000+ elements is going to be slower then querying a db.

将php数组批量插入db并在sql中查询可能更有效。批量插入有像表类型(MyISAM | InnoDB等),禁用键,大量索引的等等等等等。

it could be more efficient to bulk insert the php array to db and query in sql. bulk inserts have considerations like table type (MyISAM|InnoDB etc), disabling keys, large amounts of index's blah blah blah.

最后你需要进行基准测试。

at the end you'll need to benchmark.

这篇关于SQL查询与PHP中的条件的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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