在PHP中运行三个数据库的四个查询

时间:2010-11-30 16:16:00

标签: php mysql count

我对PHP和MySQL相当新,并且我已经在不同的地方阅读了我已经设法将这个脚本拼凑在一起的东西,不幸的是输出不是我预期的,我得到了很多: / p>

Buffer Status 2H: Notice: Undefined variable: row in /var/www/secretbit/allbuff.php on line 53 0 records. <br />
Buffer Status TC: Notice: Undefined variable: row in /var/www/secretbit/allbuff.php on line 54 0 records. <br />
Buffer Status ST: Notice: Undefined variable: row in /var/www/secretbit/allbuff.php on line 55 0 records. <br />
Buffer Status 3C: Notice: Undefined variable: row in /var/www/secretbit/allbuff.php on line 56 0 records <br />

以下是我用来编译这个怪物的代码:

 <?php

 error_reporting(-1);
 ini_set('display_errors', true);

 $con = mysqli_connect(
   '192.168.20.10',
   'root2',
   'password',
   'contaque'
 );

 $con2 = mysqli_connect(
   '192.168.20.222',
   'root2',
   'password',
   'contaque'
 );

 $con3 = mysqli_connect(
   '192.168.20.8',
   'root2',
   'password',
   'contaque'
 );

 $res = mysqli_query(
 $con,
  "SELECT COUNT(*) AS 'total1' FROM contaque_hopper WHERE  campaign_id = 'CLOSERUK';"
 );

 $res = mysqli_query(
 $con2,
  "SELECT COUNT(*) AS 'total2' FROM contaque_hopper WHERE  campaign_id = 'CLOSERTC';"
 );

 $res = mysqli_query(
 $con2,
  "SELECT COUNT(*) AS 'total3' FROM contaque_hopper WHERE  campaign_id = 'CLOSERST';"
 );

 $res = mysqli_query(
 $con3,
  "SELECT COUNT(*) AS 'total4' FROM contaque_hopper WHERE  campaign_id = 'CLOSER3C';"
 );

 echo 'Buffer Status 2H: ', (int)$row['total1'], ' records. <br />';
 echo 'Buffer Status TC: ', (int)$row['total2'], ' records. <br />';
 echo 'Buffer Status ST: ', (int)$row['total3'], ' records. <br />';
 echo 'Buffer Status 3C: ', (int)$row['total4'], ' records. <br />';

 ?>

1 个答案:

答案 0 :(得分:4)

看起来$row未定义。我想您可能需要使用方法mysqli_fetch_assoc()来获取查询结果。