如何修复mysqli_query()和mysqli_fetch_array()错误

时间:2016-08-01 11:48:44

标签: php mysql mysqli

我正在尝试创建一个PHP脚本,在按钮单击时将文本从文件打印到网站。

这是我的代码:

static System.Byte[] test()
{
    str _filePath = "C:\\Users\\Harry\\Desktop\\ABC.PDF";

    System.Byte[]           pdfBuffer;
    System.IO.FileInfo      fileInfo;
    System.IO.FileStream    fs;
    int                     size;
    Set                     permissionSet = new Set(Types::Class);

    permissionSet.add(new FileIOPermission(_filePath,'r'));
    permissionSet.add(new InteropPermission(InteropKind::ClrInterop));

    CodeAccessPermission::assertMultiple(permissionSet);

    //Load the file
    fileInfo = new System.IO.FileInfo(_filePath);
    //Initiallize the byte array by setting the length of the file
    size = int642int(fileInfo.get_Length());
    pdfBuffer = new System.Byte[size]();
    // Stream the file
    fs = new System.IO.FileStream(fileInfo.get_FullName(), System.IO.FileMode::Open, System.IO.FileAccess::Read);
    fs.Read(pdfBuffer, 0, pdfBuffer.get_Length());
    fs.Close();
    fs.Dispose();

    //Revert the access
    CodeAccessPermission::revertAssert();

    return pdfBuffer;    
}

这是每次单击按钮时出现的错误: image of error

任何人都知道如何解决这个问题?

2 个答案:

答案 0 :(得分:0)

您需要在修改过的脚本中引入大多数mysqli_ *函数所需的数据库连接变量{1}}:

$con

此外,在这种情况下,您需要传递mysqli_query(),<?php $con = mysqli_connect("host", "username", "password", "dbname") or die(mysqli_error($con)); if (isset($_POST['button'])) { $result = mysqli_query($con, "SELECT name,lastname FROM users ORDER BY RAND()"); $name = null; $lastname = null; while ($row = mysqli_fetch_array($result)) { $name = $row['name']; $lastname = $row['lastname']; } echo '<p><small>Output:</small></p><pre style="min-width:auto;display:table;">' . $name . '_' . $lastname . '</pre>Format: <b>name_lastname</b> <span style="width:310px;">'; } ?> <form method="POST"> <button type="submit" class="btn btn-default" name="button">button</button> <br> </form> 返回的结果集标识符。一切都可以在W3Schools找到。

答案 1 :(得分:0)

第一次错误

  1. 您需要确保自己拥有MySql
  2. 的访问权限
  3. 确保您已在

    中提供了所有参数(主机,用户名,密码,dbname)的所有正确值

    mysqli_connect("host", "username", "password", "dbname");

  4. 第二次错误

    mysqli_query("SELECT name,lastname FROM users ORDER BY RAND()");
    mysqli_connect有两个参数dbconnection&amp; query。请参阅mysqli_query

    while ($row = mysqli_fetch_array()) {

    中的

    第三次错误

    mysqli_fetch_array()需要至少1个参数(例如,mysqli_query()返回结果。请检查此mysqli_fetch_array

    修改后的代码

    <?php
        $conn = mysqli_connect("host", "username", "password", "dbname") or die(mysqli_error($conn));
        if (isset($_POST['button'])) {
            $result =  mysqli_query($conn, "SELECT name,lastname FROM users ORDER BY RAND()");
            $name = null;
            $lastname = null;
            while ($row = mysqli_fetch_array($result)) {
                $name = $row['name'];
                $lastname = $row['lastname'];
            }
            echo '<p><small>Output:</small></p><pre style="min-width:auto;display:table;">' . $name . '_' . $lastname . '</pre>Format: <b>name_lastname</b> <span style="width:310px;">';
        }
    ?>
    <form method="POST">
        <button type="submit" class="btn btn-default" name="button">button</button>
        <br>
    </form>