php - 使用 TCPDF 的警告函数 mysql_query() 和 mysql_fetch_array()

标签 php mysql warnings tcpdf

<分区>

我正在尝试从 mysql 打印数据,但出现以下错误:

Warning: mysql_query() expects parameter 1 to be string, resource given in ..

Warning: mysql_fetch_array() expects parameter 1 to be resource, null given in ..

TCPDF ERROR: Some data has already been output, can't send PDF file

我已经从以下链接中了解到,但仍然收到警告:

这是代码:

    $con=mysql_connect('localhost','root','','bkd_rev');
    $sql = 'select * from tbl';                       
    $result = mysql_query($con,$sql);

    if($result === FALSE) {
        die(mysql_error());
    }

    while($row = mysql_fetch_array($result))
    {
                    $id       = $row['id'];
                    $nam      = $row['name'];                       
        $tbl    .= '<tr> 
                <td>'.$id.'</td><td>'.$nam.'</td><td>
                </tr>';
    }

最佳答案

mysql_query 的正确语法与你的相反。来自文档

mixed mysql_query ( string $query [, resource $link_identifier = NULL ] )

所以你需要改成

$result = mysql_query($sql,$con);

由于不需要连接链接,如果您只使用数据库连接,您可能不会使用它

$result = mysql_query($sql);

您可能需要在连接后选择您的数据库

bool mysql_select_db ( string $database_name [, resource $link_identifier = NULL ] )

作为旁注,我建议您切换到 PDOmysqlimysql_* api 已被弃用,很快将不再维护

关于php - 使用 TCPDF 的警告函数 mysql_query() 和 mysql_fetch_array(),我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/22225630/

相关文章:

php - 如何从 WooCommerce 中的订单中获取客户详细信息?

php - 如何在 PHP、HTML 标签中回显

php - "Notice: Undefined variable"、 "Notice: Undefined index"、 "Warning: Undefined array key"和 "Notice: Undefined offset"使用 PHP

c - GCC 不会对从 void * 到 void ** 的隐式转换发出警告

PHP语法错误

php - 迁移后测试数据(HTML -> PHP -> SQL)

php - 处理数据库连接中的各种错误-有些不起作用?

php - 使用 PHP 将一条 MySQL 语句转化为多个 PHP 变量

mysql查询左连接三个表显示所有数据

python - Python 文件编辑器中的完成和 linting 在当前 session 期间将不起作用,或者停止工作