php
  • mysqli
  • 2013-03-27 3 views -3 likes 
    -3

    아래의 MySQL 쿼리를 MySQLi (준비된 명령문)로 변경하려고했지만 여러 행을 선택 했으므로 어떻게해야할지 모르겠다. 누구든지 올바른 방향으로 나를 가리킬 수 있습니다.여러 행 선택 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'; 
         } 
    
    +0

    가장 큰 차이점은 변수에 자리 표시자를 사용하고 나중에 값을 바인딩한다는 것입니다. 설명서를 확인 했습니까? – jeroen

    +0

    다른 사람? 정말 도움이 필요합니다. – Magna

    답변

    -1

    그것을 좀 걸릴 수 있습니다,이 http://www.php.net/manual/en/mysqli-result.fetch-object.php 좀 걸릴 수 있습니다 나는 매우 간단했습니다. 질문을 할 때마다 왜 투표를해야하는지 모르겠습니다.

    $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'; 
        } 
    
    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(); 
    
    +0

    코드를 복사했지만 작동하지 않습니다. – Magna

    0

    Mysqli는 고전 MySQL의 API를 통해 객체 지향 인터페이스를 제공으로 변경하는 것입니다. 또한 트랜잭션, 준비된 명령문, 다중 명령문을 지원합니다.

    당신이 연관 배열로 행을 인출하려면 개체

    으로 행을 인출하려는 경우 당신은 당신은 http://www.php.net/manual/en/mysqli-result.fetch-assoc.php

    +0

    나는 설명서를 결코 얻지 않는다. – Magna

    관련 문제