使用mysqli获取行

时间:2013-11-21 15:59:01

标签: php mysqli

它是一个简单的代码。我希望每次上传文件时都在数据库中保留记录。当每次上传任何文件时,我希望用户从数据库中查看他/她所有上传的文件。上传文件时保存的记录工作正常。但是在获取包含所有上载文件信息的表时会出现问题。

//connetion code 
$con = mysqli_connect("localhost", "root", "", "sss");

if (mysqli_connect_errno()) 
{
    printf("Connect failed: %s\n", mysqli_connect_error());
    exit();
}

//file upload code
move_uploaded_file($_FILES["file"]["tmp_name"],"C:/xampp/htdocs/" . $_FILES["file"]["name"]);
mysqli_query($con, "INSERT INTO uploads ( filename, uploaded_on) VALUES ( '{$_FILES['file']['name']}', NOW());");
echo "Stored in: " . "C:/xampp/htdocs/" . $_FILES["file"]["name"];

//fetch rows 
$result =mysqli_query($con, "select * from uploads");

while ($row = mysqli_fetch_array($result))
{
    printf ("%s\n", $row);
}

mysqli_close($con);
}

我觉得编码有一些严重的问题。这是我第一次在mysqli工作,之前我习惯使用mysql编写代码。需要帮助来了解实际问题和解决方案。

编辑: 它返回这个,

Notice: Array to string conversion in C:\xampp\htdocs\sss\upload_file.php on line 68
Array

Notice: Array to string conversion in C:\xampp\htdocs\sss\upload_file.php on line 68
Array

Notice: Array to string conversion in C:\xampp\htdocs\sss\upload_file.php on line 68
Array

但不幸的是,这段代码是巨大代码的一部分。所以这里第68行是$result = mysqli_query($con, "select * from uploads");开始的行。

1 个答案:

答案 0 :(得分:2)

$result =mysqli_query($con, "select * from uploads");
while ($row = mysqli_fetch_assoc($result))
   {
      printf ("%s\n", $row['column_name_1']);
      printf ("%s\n", $row['column_name_2']);
      printf ("%s\n", $row['column_name_3']);
   }
mysqli_close($con);

但是你应该认真考虑查看代码的安全性。