导致“数据已输出”的 tcpdf 文件位于名为 tcpdf.php 的 tcpdf 文件夹中。你可以修改它:
添加行ob_end_clean(); 如下(倒数第三行):
public function Output($name='doc.pdf', $dest='I') {
//LOTS OF CODE HERE....}
switch($dest) {
case 'I': {
// Send PDF to the standard output
if (ob_get_contents()) {
$this->Error('Some data has already been output, can\'t send PDF file');}
//some code here....}
case 'D': { // download PDF as file
if (ob_get_contents()) {
$this->Error('Some data has already been output, can\'t send PDF file');}
break;}
case 'F':
case 'FI':
case 'FD': {
// save PDF to a local file
//LOTS OF CODE HERE..... break;}
case 'E': {
// return PDF as base64 mime email attachment)
case 'S': {
// returns PDF as a string
return $this->getBuffer();
}
default: {
$this->Error('Incorrect output destination: '.$dest);
}
}
ob_end_clean(); //add this line here
return '';
}
现在让我们看看你的代码。
我看到您混淆了 $rs 和 $sql 。这是两个不同的东西一起工作。
$conn=odbc_connect('northwind','****','*****');
if (!$conn) {
exit("Connection Failed: " . $conn);
}
$sql="SELECT * FROM products"; //is products your table name?
$rs=odbc_exec($conn,$sql);
if (!$rs) {
exit("Error in SQL");
}
while (odbc_fetch_row($rs)) {
$prodname=odbc_result($rs,"Product Name"); //but preferably never use spaces for table names.
$prodid=odbc_result($rs,"ProdID"); //prodID is assumed attribute
echo "$prodname";
echo "$prodid";
}
odbc_close($conn);
now you can use the $prodname and output it to the TCPDF output.
我假设您正在连接到 MS 访问数据库。