在MySQLi中的select语句中获取绑定参数错误

时间:2018-12-11 20:47:29

标签: php mysqli prepared-statement

我在下面添加了一个精选代码段。为什么在Private Sub UserForm_Initialize() Dim shtData As Worksheet Dim Year2CourseRange As Range, HeaderRange As Range, m, c As Range Set shtData = ThisWorkbook.Sheets("Year2") With shtData Set Year2CourseRange = .Range("A:A") Set HeaderRange = .Range(.Range("B2"), .Cells(2, 500).End(xlToLeft)) End With 'you'll need to fix this part.... BNumberTxt = Row.Offset(0, -7) 'etc 'find a matching row: Match() is a good approach here m = Application.Match(BNumberTxt, Year2CourseRange, 0) 'loop over all the column headers For Each c In HeaderRange.Cells 'Assumes all checkboxes are named "CHK[ColumnHeaderHere]" With Me.Controls("CHK" & c.Value) If IsError(m) Then .Value = False 'clear all if no match Else .Value = (UCase(shtData.Cells(m, c.Column)) = "X") 'set if "x" End If End With End If End Sub 上出现以下错误?

  

未捕获的错误:在布尔值上调用成员函数bind_param()

代码:

bind_param()

1 个答案:

答案 0 :(得分:1)

Mysqli prepare可以在绑定之前返回false,您必须检查它是否有错误。 在php.net中查看这篇文章

http://php.net/manual/en/mysqli.error.php

    $sessien = $_POST['xsession'];
    $conn = new mysqli(DB_SERVER, DB_USERNAME, DB_PASSWORD, DB_NAME);
    /* check connection */
    if ($conn->connect_errno) {
        printf("Connect failed: %s\n", $conn->connect_error);
        exit();
    }
    $query = "SELECT `post` FROM `user` WHERE session=? ORDER BY `thedate` DESC ";
    $stmt = $conn->prepare($query);
    if ($stmt) {
        $stmt->bind_param("s", $sessien);

        //bind Response variables
        $stmt->bind_result($post);
        $stmt->execute();
        while ($stmt -> fetch()) {
                echo "$post<br>";
        }
        $stmt->close();
    }else{
           //error
           var_dump($conn->error);
    }