我會親切地appriciate,如果有人不能提示我如何返回一個資源與mysqli_query,而不是一個對象,因爲每當我用它與mysqli_field_name或mysql_fetch_row它返回我這個錯誤「mysql_field_name()期望參數1是資源,對象給予「。並且介意你不是很熟悉mysqli方法。一些幫助將被appriciated.Below這裏是我的代碼的全部細節。mysqli_query返回對象不是資源
<?php
$dns="mysql:dbname=name";
$username="name";
$password="";
$con = new mysqli('localhost', 'root', '', 'oysg');
$export=mysqli_query($con,"SELECT * FROM applicant");
$header = '';
$data ='';
// $export = $stmt;
// extract the field names for header
$fields = 25;
for ($i = 0; $i < $fields; $i++)
{
$header .= mysql_field_name($export , $i) . "\t";
echo $header;
}
echo '<br>';
echo '<br>';
// foreach ($fields2 as $headers)
// {
// $header .= $headers. "\t";
// echo $header;
// }
// export data
while($row = mysql_fetch_row($export))
{
$line = '';
foreach($row as $value)
{
if ((!isset($value)) || ($value == ""))
{
$value = "\t";
}
else
{
$value = str_replace('"' , '""' , $value);
$value = '"' . $value . '"' . "\t";
}
$line .= $value;
}
$data .= trim($line) . "\n";
}
$data = str_replace("\r" , "" , $data);
if ($data == "")
{
$data = "\nNo Record(s) Found!\n";
}
// allow exported file to download forcefully
header("Content-type: application/octet-stream");
header("Content-Disposition: attachment; filename=export.xml");
header("Pragma: no-cache");
header("Expires: 0");
print "$header\n$data";
?>
在此先感謝
你在混合'mysqli_ *'和'mysql_ *'擴展嗎?或者是一個錯字? – mithunsatheesh 2014-10-03 16:29:38