2014-02-11 40 views
-2

这里是我的代码:PHP get_result()导致页面无法显示

/* database connection tested and working*/ 

if (!($sql = $mysqli->prepare("SELECT username FROM users WHERE username=?"))) 
{ 
    echo "Prepare failed"; 
} 

if (!$sql->bind_param("i", `ryan`)) 
{ 
    echo "Binding parameters failed"; 
} 

if (!$sql->execute()) 
{ 
    echo "Execute failed"; 
} 

到目前为止,一切正常,没有错误显示,我可以print_r$sql阵列。

只要我添加以下代码:

$result = $sql->get_result(); 

我得到一个错误说“网站无法显示该页面”。我删除它,它工作正常。

PS:这是一个打印出来$sql

mysqli_stmt Object ([affected_rows] => -1 [insert_id] => 0 [num_rows] => 0 [param_count] => 1 [field_count] => 1 [errno] => 0 [error] => [error_list] => Array () [sqlstate] => 00000 [id] => 1) 

回答

0

尝试添加几行代码的错误报告。您可能会更好地描述问题。如果你已经安装了MySQLnd

ini_set('display_errors',1); 
ini_set('display_startup_errors',1); 
error_reporting(-1); 
0

第一件事:

if (!$sql->bind_param("i", `ryan`)) 
{ 
    echo "Binding parameters failed"; 
} 

这应该是:

if (!$sql->bind_param("s", 'ryan')) 
{ 
    echo "Binding parameters failed"; 
} 

你有backtics ``包装ryani这对于整数字符串。

-i corresponding variable has type integer 

-d corresponding variable has type double 

-s corresponding variable has type string 

-b corresponding variable is a blob and will be sent in packets