如何从 MySQL 中只获取与 id 对应的文本并将其作为变量存储在 PHP 中
How to get only a text corresponding to the id from MySQL and store it as a variable in PHP
我是 PHP 的初学者,我想知道如何从相应的 ID 中获取一些文本并将其作为变量存储在 PHP 中。
table 就像
ID----NAME----ACCOUNT----PASSWORD
1----name1----accont1----password2
2----name2----accont2----password2
3----name3----accont3----password3
现在,如果我想以文本形式获取 account2 并将其保存在变量(例如 acc2)中,那么我应该怎么做。假设我在 connect.php 中有连接信息。
编辑:我想 select account2 使用来自 ID 2 select 帐户的 ID。
提前致谢!!!
假设您使用 MySQL,table 被命名为用户并且您正在使用 PDO,这将得到您需要的:
$stmt = $conn->query("SELECT * FROM users WHERE ID = 2");
$row = $stmt->fetch()
$account = $row['ACCOUNT']
我是 PHP 的初学者,我想知道如何从相应的 ID 中获取一些文本并将其作为变量存储在 PHP 中。
table 就像
ID----NAME----ACCOUNT----PASSWORD
1----name1----accont1----password2
2----name2----accont2----password2
3----name3----accont3----password3
现在,如果我想以文本形式获取 account2 并将其保存在变量(例如 acc2)中,那么我应该怎么做。假设我在 connect.php 中有连接信息。 编辑:我想 select account2 使用来自 ID 2 select 帐户的 ID。
提前致谢!!!
假设您使用 MySQL,table 被命名为用户并且您正在使用 PDO,这将得到您需要的:
$stmt = $conn->query("SELECT * FROM users WHERE ID = 2");
$row = $stmt->fetch()
$account = $row['ACCOUNT']