如何將這些元素放置到變量中?如何將數據庫中的SELECTED元素放入變量
$user_information = $connect->prepare("SELECT email, gender, firstname, middlename, FROM members");
像
$firstname = 'firstname';
$gender = 'gender';
$email = 'email';
我怎麼能提前
如何將這些元素放置到變量中?如何將數據庫中的SELECTED元素放入變量
$user_information = $connect->prepare("SELECT email, gender, firstname, middlename, FROM members");
像
$firstname = 'firstname';
$gender = 'gender';
$email = 'email';
我怎麼能提前
做到這一點
謝謝如果你正在使用PHP和PDO,你可以在獲取方法使用,以獲得一個使用PDO::FETCH_OBJ
的對象。 http://de3.php.net/manual/en/pdostatement.fetch.php
$result = $sth->fetch(PDO::FETCH_OBJ);
print $result->NAME;
list($email, $gender, $firstname, $middlename) = $user_information;
欲瞭解更多信息檢查LIST function @ PHP docs。
如果你是,如果你使用的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();
如果它返回一個對象,你可以得到它喜歡用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"];
您正在使用PDO或mysqli? –
請參閱[bind_result](http://www.php.net/manual/en/mysqli-stmt.bind-result.php)。 – Rikesh