doujiaoang69440 2013-06-15 15:11
浏览 29

多个数据库连接减慢了我的网站PHP MySQL

I am new and I tried to find my answer in the questions but I did not find something even close.

I have a website that is displaying data from 6 different databases. This is the code i use to connect the databases:

<?php 
$con=mysqli_connect("server","user","password","database");
$result = mysqli_query($con,"SELECT count(*) as new_orders FROM orders where print=0");
while($row = mysqli_fetch_array($result)){
echo $row['new_orders'];
}
mysql_close($con);
?>

I used this code and only change the connection credentials for all the 6 databases since they have the same table. The problem is that I have to used the 6 connections in the same php page but every time I open my file dashboard.php, it shows all the information I need from the 6 databases but it takes around 30 seconds to load the page.

As you can see my query is very simple, just count the orders and that's it ! ... I was researching and I found that I probably need indexes, well I create the indexes for the tables in the databases but nothing changed.

Could you please help me with this? Any ideas of what the problem may be. This page is like the first page of my website so it is always visit and people have to wait like 30 seconds to see the page.

Thank you for the help you can provide me

Regards,

Oscar Rabines

  • 写回答

3条回答 默认 最新

  • duanjucong3124 2013-06-15 16:01
    关注

    Did you know you can improve your website performance by using gzip or something similar?
    Also I recommend using a single class for the MySQL server connection. It makes your code much better readable.
    Which indexes do you used?
    Also try to use just one or two databases on one server with tables instead of databases.

    评论

报告相同问题?

悬赏问题

  • ¥15 基于卷积神经网络的声纹识别
  • ¥15 Python中的request,如何使用ssr节点,通过代理requests网页。本人在泰国,需要用大陆ip才能玩网页游戏,合法合规。
  • ¥100 为什么这个恒流源电路不能恒流?
  • ¥15 有偿求跨组件数据流路径图
  • ¥15 写一个方法checkPerson,入参实体类Person,出参布尔值
  • ¥15 我想咨询一下路面纹理三维点云数据处理的一些问题,上传的坐标文件里是怎么对无序点进行编号的,以及xy坐标在处理的时候是进行整体模型分片处理的吗
  • ¥15 CSAPPattacklab
  • ¥15 一直显示正在等待HID—ISP
  • ¥15 Python turtle 画图
  • ¥15 stm32开发clion时遇到的编译问题