我在本地主机中开发了以下脚本(使用 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 ||