2010-02-22 92 views
1

我敢肯定,这将有人没有时间。Mysqli SELECT语句的问题不会返回任何东西

我知道MySqli在这个服务器上工作,因为我试过插入,他们工作正常。

我也知道,我试图获得的信息是在数据库中,我可以连接到数据库没有任何问题。但我不能为了我的生活找出为什么这不起作用。我已经尝试了OO和程序,但都没有工作。有人能告诉我我应该做什么吗?由于

$table = 'newcms_broadcasting'; 

$sql = "SELECT first_info1 FROM $table WHERE region_id = ?"; 

echo $sql; 

//echo $sql; 


$region = '1'; 

$stmt = mysqli_prepare($connection, $sql); 

    mysqli_stmt_bind_param("s", $region); 
    mysqli_execute(); 
    mysqli_bind_result($result); 

    echo 'blah'; 

    // display the results 
    mysqli_fetch($stmt); 

    echo "name: $result"; 

    // clean up your mess! 
    mysqli_close($stmt); 

回答

1

当使用程序的风格,你应该通过$语句到mysqli_stmt_bind_param,mysqli_stmt_execute,mysqli_bind_result等

mysqli_stmt_bind_param($stmt, "s", $region); 
mysqli_stmt_execute($stmt); 
mysqli_bind_result($stmt, $result); 
while (mysqli_stmt_fetch($stmt)) { 
    print_r($result); 
} 
+0

真棒!知道这是我遗漏的东西!感谢这一点。它现在可以工作! – Drew 2010-02-22 10:57:51

1

你忘了,包括在结合所导致的编译声明:

mysqli_stmt_bind_result($stmt, $result); 

也注意,mysqli_fetch已被弃用,你尝试过使用的是经典取while循环?

while (mysqli_stmt_fetch($stmt)) { 
    print_r($result); 
} 
+0

似乎并没有这样的伎俩我,我很害怕。谢谢 – Drew 2010-02-22 10:56:06