PHP远程MySQL数据获取大小限制问题


PHP remote MySQL data fetching size limit issue

我试图远程连接到服务器的MySQL数据库并拉行。但是我有这个问题:

我能够拉一些特定的列数据,但不能拉整行。

示例:

-- Query 1
SELECT  id, name, link, cat, image, title, features
FROM products 
WHERE data_ready=1 
ORDER BY id ASC
LIMIT 0,1

但是这行不通:

-- Query 2
SELECT *
FROM products
WHERE data_ready=1
ORDER BY id ASC
LIMIT 0,1  

-- Query 3
SELECT  id, name, link, cat, image, title, features, description
FROM products
WHERE data_ready=1
ORDER BY id ASC
LIMIT 0,1

请注意,在查询号3中,我试图再拉一个列description,这不在查询1中。描述字段的长度为1314。

有些东西限制了我的数据量,可以提取,但我如何找到什么和如何修复它?

顺便说一下,SELECT @@max_allowed_packet产1048576。


编辑

通过'不工作'意味着查询没有返回任何东西,但页面继续加载并最终超时。

是的,我已经测试了查询直接在Mysql和它工作得很好,

实际上我有一个中央数据库服务器和许多客户端服务器,他们都从中央服务器获取数据。我能够获取整个数据到所有的客户端服务器除了一个,在那里我面临这个问题。所以我相信这与某种php.ini设置有关。我比较了所有服务器的phpinfo()设置,但无法找出可能导致此限制的原因。

SHOW TABLE STATUS like 'products';

Space usage
Data    438.8   MiB
Index   7.5 MiB
Total   446.3   MiB
Row Statistics
Format  Compact
Collation   latin1_swedish_ci
Next autoindex  2,015,640
Creation    May 19, 2014 at 01:46 PM

——更多信息——我的Php代码很简单:

<?php
$conn=@mysql_pconnect("xx.xx.xx.xx","DBNAME","DBPASS")or die("ERROR CONNECTING TO MYSQL SERVER");
@mysql_select_db("DBUSERNAME",$conn)or die("ERROR CONNECTING TO DATABASE");
$sql="select  id,pid,name,link,cat,image,title,features,price,description from products order by id asc limit 0,1";
$execute=mysql_query($sql,$conn);
$row=mysql_fetch_assoc($execute);
print_r($row);
?>

下面两个查询返回数据:

Query 4 - select  id,pid,name,link,cat,image,title,features from products order by id asc limit 0,1
Query 5 - select  id,pid,name,link,cat,image,title,description from products order by id asc limit 0,1

但是如果我试图同时获取功能和描述,那么脚本永远不会完成,最终超时。例如

Query 6 - select  id,pid,name,link,cat,image,title,features ,description from products order by id asc limit 0,1

相同的代码是在其他两个服务器我有工作。但是我不知道这个服务器配置有什么问题:/

故障排除问题

有可能,但不确定,你遇到了MySQL服务器设置max_allowed_packet的麻烦。

试着找出你的description字段的大小为您无法获取的特定行。

SELECT id, name, link, cat, image, title, features, 
       LENGTH(description)
  FROM products
 WHERE data_ready=1
 ORDER BY id ASC
 LIMIT 0,1

如果description的长度出奇地大,这可能是您的问题。是1314,这不是问题

给出这个命令:

SELECT @@max_allowed_packet : **it's 1 048 576 which is plenty** 

对于您的description来说是否太小或几乎太小?看到这个:

http://dev.mysql.com/doc/refman/5.1/en/packet-too-large.html

下一步:查看驱动MySQL的特定php代码

你为什么使用mysql_pconnect?,你有一个很好的理由吗?如果不是,请切换到mysql_connect。无论如何,让这些代码与mysql_connect一起工作,然后切换回来。

为什么在pconnect中给出数据库名,而在select_db中给出用户名?你确定那些是对的吗?

问题中发布的代码需要清理,以正确检查错误并跟踪可能卡住的地方。您还需要在完成后释放结果集。试试这样的代码。请注意,我没有调试它,这取决于你。

 $execute=mysql_query($sql,$conn);
 if (!$execute) {
     die "Query ($sql) failed: " . mysql_error();
 }
 while ($row=mysql_fetch_assoc($execute)) {
    /* loop through a result set even if you don't think you need to. */
    print_r($row);
 }
 mysql_free_result($execute);

我认为你应该转义你正在查询的字段,用反引号`:

-- Query 3
SELECT  `id`, `name`, `link`, `cat`, `image`, `title`, `features`, `description`
FROM products
WHERE data_ready=1
ORDER BY id ASC
LIMIT 0,1

因为像description, titlematch这样的关键字可能会被MySQL错误地解释。