使用mysqli获取行 [英] Fetch rows using mysqli

查看:74
本文介绍了使用mysqli获取行的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

它是一个简单的代码.我想每次上传文件时都在数据库中保留一条记录.而且,每次每次上传任何文件时,我都希望用户从数据库中以串行方式查看他/她的所有上传文件.上传文件时保持记录良好.但是在获取包含所有上载文件信息的表时出现了问题.

its a simple code. I want to keep a record in the database each time when a file is being uploaded. And when each time any file is being uploaded I want the user to see he/her's all uploaded files in a serial from the database. The record keeping while uploading file works fine. But the problem appears while fetching the table containing all the uploaded file information.

//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进行编码.需要帮助来了解实际问题和解决方案.

I can feel that there are some serious problem in coding. This is my first time working in mysqli, before I used to code using mysql. need help to know the actual problem and the solution.

它返回此,

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");的开始行.

but unfortunately this code is a part of a huge code. so here line 68 is the line where the $result = mysqli_query($con, "select * from uploads"); starts.

推荐答案

$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);

但是您应该认真考虑一下代码的安全性.

But you should seriously consider looking at the security of your code.

这篇关于使用mysqli获取行的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆