没有数据库连接但没有错误

时间:2012-06-26 17:29:16

标签: php

这是我的数据库连接代码和查询代码:

// Connecting, selecting database
$link = mysql_connect('MySQLA22.webcontrolcenter.com', 'shudson', '*******')
   or die('Could not connect: ' . mysql_error());

mysql_select_db('henrybuilt') or die('Could not select database');

$sql = "SELECT ID, vcImageName FROM corp_images WHERE idPage = 6";
$query = mysql_query($sql) or die ("Error");
  • 连接,选择或查询
  • 时没有'或死'错误
  • 没有error_log文件
  • 如果我在sql浏览器中运行它,则执行sql查询

发生了什么事?

2 个答案:

答案 0 :(得分:2)

$sql = "SELECT ID, vcImageName FROM corp_images WHERE idPage = 6"

它失踪了;

$sql = "SELECT ID, vcImageName FROM corp_images WHERE idPage = 6";

答案 1 :(得分:1)

出现正确...尝试添加此适应代码from the manual以进一步调试并查看您所学的内容:

// This shows the actual query sent to MySQL, and the error. Useful for debugging.
if (!$query) {
    $message  = 'Invalid query: ' . mysql_error() . "\n";
    $message .= 'Whole query: ' . $sql;
   die($message);
}

// Use result
// Attempting to print $result won't allow access to information in the resource
// One of the mysql result functions must be used
// See also mysql_result(), mysql_fetch_array(), mysql_fetch_row(), etc.
while ($row = mysql_fetch_assoc($query)) {
    echo $row['ID'];
    echo $row['vcImageName'];
}