dongli8466 2015-12-15 18:46
浏览 85

Sql高效快速搜索

I am making a large website using php and sql that will contain many users and i need to make my database as fast as possible. This is the code that get posts value from database table called upload and store them in an array

//connect to database
$a = 'localhost';
$b = 'root';
$c = '';
$d = 'petsnote';
$connect = mysqli_connect($a, $b, $c, $d);

//get posts images variables
$images = array();
$cat = array();
$id = array();

//get posts info
if($connect){
    $query = "SELECT * FROM `upload` WHERE `Active`='1'";
    if($query_run = mysqli_query($connect, $query)){
        while($get = mysqli_fetch_assoc($query_run)){
            array_push($images, $get['Image_Name']);
            array_push($cat, $get['PostCategory']);
            array_push($id, $get['Id']);
        }

        $loop = count($images);
    }
}

I get all the post information from the database and store them in an array and use that array to view only some values.. Is this an efficient, professional and fast way to do things?

  • 写回答

1条回答 默认 最新

  • dongluobei9359 2015-12-15 20:05
    关注

    Your query needs only to ask for things it will use:

    SELECT Id, Image_Name, PostCategory FROM upload WHERE Active='1'
    

    But this will not meaningfully speed up anything.

    What's more important is the database structure. From MySQL run SHOW CREATE TABLE upload and ensure that every column you will search on (e.g. Active in this case) is indexed.

    Though again, unless you're dealing with tens of thousands of rows, you're not going to see much of a difference.

    评论

报告相同问题?

悬赏问题

  • ¥15 使用yolov5-7.0目标检测报错
  • ¥15 对于这个问题的解释说明
  • ¥200 询问:python实现大地主题正反算的程序设计,有偿
  • ¥15 smptlib使用465端口发送邮件失败
  • ¥200 总是报错,能帮助用python实现程序实现高斯正反算吗?有偿
  • ¥15 对于squad数据集的基于bert模型的微调
  • ¥15 为什么我运行这个网络会出现以下报错?CRNN神经网络
  • ¥20 steam下载游戏占用内存
  • ¥15 CST保存项目时失败
  • ¥20 java在应用程序里获取不到扬声器设备