MySQL Prepared Statement,写入多行

时间:2014-01-06 23:16:29

标签: php mysql sql prepared-statement

到目前为止,我已经使用预准备语句从数据库中获取一行。但是如何在页面上写入多行。在网上看,人们似乎只是在展示如何获得一排。

if ($count_sets->num_rows > 0) {
        $query = "SELECT id,jpg,udate,imageset FROM images WHERE dodelete = ? AND udate = ? AND imageset = ?";
        if ($stmt = $mysqli->prepare($query)) {
            //echo "Prepare failed: (" . $mysqli->errno . ") " . $mysqli->error;
            $stmt->bind_param("isi",$deleted,$session_date,$imageset);
            $stmt->execute();
            $stmt->store_result();

            //Get result
            $stmt->bind_result($result_id,$result_jpg,$result_date,$result_imageset);

            //Number of rows returned
            $count_rows = $stmt->num_rows;
        }
    } else {
        echo "No images to process, do an upload first!";   
    }
$folder = str_replace("/", "", $session_date);

            if ($count_rows > 0) {
                echo "hel<br />";
                echo $result_jpg[0];
            }

1 个答案:

答案 0 :(得分:0)

找到一些示例代码:

$db = new mysqli("host","user","pw","database");
$stmt = $db->prepare("SELECT * FROM mytable where userid=? AND category=? ORDER BY id DESC");
$stmt->bind_param('ii', intval($_GET['userid']), intval($_GET['category']));
$stmt->execute();

$stmt->store_result();
$stmt->bind_result($column1, $column2, $column3);

while($stmt->fetch())
{
    echo "col1=$column1, col2=$column2, col3=$column3 \n";
}

$stmt->close();

以下部分我不知道该怎么做。

while($stmt->fetch())
    {
        echo "col1=$column1, col2=$column2, col3=$column3 \n";
    }