undefined function mysqli_stmt_init() php error

冷暖自知 提交于 2019-12-31 04:45:31

问题


I'm new to using php mysqli prepared statements. No matter what I try I always get this error message.

Fatal error: Call to undefined function mysqli_stmt_init() in...(etc)

I have close my database link further below in my code, it isn't show here. Here is my code:

$link = mysqli_connect($mysql_host, $mysql_user, $mysql_password, $mysql_database);
if (mysqli_connect_errno()) {
    echo 'We\'re having problems connecting right now. Please try again later.';
    exit();
}
$email_query = mysqli_stmt_init($link);
if(mysqli_stmt_prepare($email_query, "SELECT * FROM users WHERE email=?")){
mysqli_stmt_bind_param($email_query, "s", $email);
mysqli_stmt_execute($email_query);
mysqli_stmt_store_result($email_query);
$exists_email = mysqli_stmt_num_rows($email_query);

mysqli_stmt_close($email_query);

The line number in the error corresponds to the init line in the code.


回答1:


You don't need mysqli_stmt_init(). Just issue your prepared statement directly.

if(mysqli_prepare($link, "SELECT * FROM users WHERE email=?")){
    mysqli_stmt_bind_param($email_query, "s", $email);
    mysqli_stmt_execute($email_query);
    mysqli_stmt_store_result($email_query);
    $exists_email = mysqli_stmt_num_rows($email_query);
    mysqli_stmt_close($email_query);
}


来源:https://stackoverflow.com/questions/28488768/undefined-function-mysqli-stmt-init-php-error

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!