php,mysql准备好的语句

发布于 2024-10-08 08:35:01 字数 648 浏览 0 评论 0原文

function addAlbum($album){
        $connection = mysqli_connect(HOST,USER,PASS,DATABASE);
        $stmt = mysqli_prepare($connection,'INSERT INTO `'.TABLE_ALBUMS.'` (albumName) VALUES (":album")');
        mysqli_stmt_bind_param($stmt,':album');
        $result = mysqli_stmt_execute($stmt);

            if($result){
                return true;
            } else {
                return false;
            }

    }

我收到此错误:

mysqli_stmt_bind_param() [function.mysqli-stmt-bind-param]: Number of elements in type definition string doesn't match number of bind variables

任何帮助将不胜感激。

function addAlbum($album){
        $connection = mysqli_connect(HOST,USER,PASS,DATABASE);
        $stmt = mysqli_prepare($connection,'INSERT INTO `'.TABLE_ALBUMS.'` (albumName) VALUES (":album")');
        mysqli_stmt_bind_param($stmt,':album');
        $result = mysqli_stmt_execute($stmt);

            if($result){
                return true;
            } else {
                return false;
            }

    }

i get this error:

mysqli_stmt_bind_param() [function.mysqli-stmt-bind-param]: Number of elements in type definition string doesn't match number of bind variables

any help would be greatly appreciated.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

站稳脚跟 2024-10-15 08:35:01

您混合了过程风格和面向对象风格

因此,要么完全使用过程风格,要么反之亦然

$sql        = 'INSERT INTO '.TABLE_ALBUMS.' (albumName) VALUES (?)';
$connection = mysqli_connect(HOST,USER,PASS,DATABASE); <- procedural style
$stmt       = mysqli_prepare($connection, $sql);       <- procedural style
mysqli_stmt_bind_param($stmt, 's', $album);            <- procedural style
$result     = mysqli_stmt_execute($stmt);              <- procedural style
... 

You have mix both procedural style and Object oriented style

So, either use entirely in procedural style or vice versus

$sql        = 'INSERT INTO '.TABLE_ALBUMS.' (albumName) VALUES (?)';
$connection = mysqli_connect(HOST,USER,PASS,DATABASE); <- procedural style
$stmt       = mysqli_prepare($connection, $sql);       <- procedural style
mysqli_stmt_bind_param($stmt, 's', $album);            <- procedural style
$result     = mysqli_stmt_execute($stmt);              <- procedural style
... 
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文