我在本地主机中开发了以下脚本(使用wamp 2.2、apache 2.2.1 windows、php 5.3.9、mysql 5.5.20)。当我将脚本上传到生产服务器(apache 2.2.29 unix、php 5.3.29、mysql 5.5.42)时,
我注意到php+pdo脚本并没有像在本地服务器中相同的脚本那样返回所有提取的行。
如果我尝试添加一个"order by"sql实例,它在本地上运行良好,但在生产服务器中,所获取的行总是相同的。
还尝试更改我的INNER JOIN表顺序,结果也是一样的。有线索吗?也许是一个错误的INNER JOIN
php+pdo:
$user = '';
$pass = '';
$dsn = 'mysql:host=myhost;dbname=mydbname;charset=utf8';
try {
$pdo = new PDO($dsn, $user, $pass);
$pdo->setAttribute(PDO::ATTR_ERRMODE, PDO::ERRMODE_EXCEPTION);
} catch (PDOException $e) {
echo 'Error: ' . $e->getMessage();
}
function Contents($id) {
global $pdo;
$stmt = $pdo->prepare('SELECT historia.id AS idhistoria, pub_us.comic, pub_us.id FROM historia INNER JOIN pub_us ON pub_us.historia = historia.id WHERE pub_us.comic = :id ORDER BY orden');
$stmt->execute(array(':id' => $id));
$data = $stmt->fetchAll(PDO::FETCH_ASSOC);
$stmt = null;
return $data;
}
$comicid = "fantasticfour/1/001";
$data = Contents($comicid);
foreach($data as $row) {
echo $row['idhistoria'];
echo " - ";
echo $row['comic'];
echo " - ";
echo $row['id'];
}
表格结构:
Table structure for historia: id(text, primary key)
Table structure for pub_us: id(int,auto increment, primary key), comic(text), historia(text, related to table historia.id)
检索到的数据:
Results in local wamp:
|| idhistoria || comic || id ||
|| fantfour-1-001b || fantasticfour/1/001 || 25356 ||
|| fantfour-1-001 || fantasticfour/1/001 || 16449 ||
|| fantfour-1-001a || fantasticfour/1/001 || 3772 ||
Results in server :
|| idhistoria || comic || id ||
|| fantfour-1-001a || fantasticfour/1/001 || 3772 ||
多亏了@rmertins线索,我解决了这个问题。
表"historia"使用INNODB引擎,表"pub_us"使用MyISAM,因此引擎之间的差异仅导致一行。
解决了将引擎更改为相同的问题(在本例中为INNODB)
感谢您的评论和线索,我希望这能帮助其他人!