2014-01-15 37 views
0

如何將這些元素放置到變量中?如何將數據庫中的SELECTED元素放入變量

$user_information = $connect->prepare("SELECT email, gender, firstname, middlename, FROM members"); 

$firstname = 'firstname'; 
$gender = 'gender'; 
$email = 'email'; 

我怎麼能提前

+0

您正在使用PDO或mysqli? –

+0

請參閱[bind_result](http://www.php.net/manual/en/mysqli-stmt.bind-result.php)。 – Rikesh

回答

1

如果你是,如果你使用的mysqli

$user_information->execute(); 
$user_information->bind_result($firstname, $gender, $email); 
$user_information->fetch(); 
printf("%s, %s, %s\n", $firstname, $gender, $email); 
$user_information ->close(); 
0

如果它返回一個對象,你可以得到它喜歡用PDO

$user_information ->execute(); 
    $result = $user_information->fetch(PDO::FETCH_ASSOC); 
    $firstname = $result['firstname']; 
    $gender = $result['gender']; 
    $email = $result['email']; 

;

$firstname = $user_information->firstname; 
$gender = $user_information->gender; 
$email = $user_information->email; 

或者如果它返回一個數組;

$firstname = $user_information["firstname"]; 
$gender = $user_information["gender"]; 
$email = $user_information["email"]; 
相關問題