-3

以下のMySQLクエリをMySQLi(準備済みステートメント)に変更したかったのですが、選択する行が複数あるため、その方法がわかりません。誰でも私を正しい方向に向けることができますか?

$check_added_files = mysql_query("select * from `vpb_uploads` where `username` = '".mysql_real_escape_string($username)."' and `firstname` = '' and `image_one` != '' and `image_two` != '' and `image_three` != '' and `image_four` != '' and `image_five` != ''");
        if(mysql_num_rows($check_added_files) == 1)
        {
            echo 'up_to_five_already';
        }
4

3 に答える 3

2

正しい方法は、それをPDOに変更することです

$sql = "select * from vpb_uploads where username=? and firstname=''
        and image_one != '' and image_two != '' and image_three != '' 
        and image_four != '' and image_five != ''";
$stm = $pdo->prepare($sql);
$stm->execute(array($username));
$files = $stm->fetchAll();
于 2013-03-27T16:03:09.037 に答える
0

mysqli は、従来の mysql api を介してオブジェクト指向インターフェイスを提供します。また、トランザクション、準備されたステートメント、複数のステートメントもサポートしています。

行をオブジェクトとしてフェッチする場合は、このhttp://www.php.net/manual/en/mysqli-result.fetch-object.phpをご覧ください。

行を連想配列としてフェッチする場合は、http: //www.php.net/manual/en/mysqli-result.fetch-assoc.php をご覧ください。

于 2013-03-27T16:03:55.143 に答える
-1

質問するたびに反対票を投じる理由がわかりません。

$mysqli = new mysqli("localhost", "root", "", "database");
    if ($mysqli->connect_errno) {
    echo "Failed to connect to MySQL: (" . $mysqli->connect_errno . ") " . $mysqli->connect_error;
    }

 $username = $_SERVER['REMOTE_ADDR']; 
    $stmt = $mysqli->prepare("select * from `vpb_uploads` where `username` = ? and `firstname` = '' and `image_one` != '' and `image_two` != '' and `image_three` != '' and `image_four` != '' and `image_five` != ''");
    $stmt->bind_param('s', $username);
    $stmt->execute();
    $stmt->store_result();

    if ($stmt->num_rows == 1) {

    echo 'up_to_five_already';
    }
于 2013-03-27T21:58:04.687 に答える