我会亲切地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