这是一种传统的方法,我可以用mysqli\u fetch\u array()函数获取所有带有数据的行并运行while循环来逐个获取它们。
$con = mysqli_connect(YOURLS_DB_HOST,YOURLS_DB_USER,YOURLS_DB_PASS);
mysqli_select_db($con,YOURLS_DB_NAME);
$users=mysqli_query($con,"SELECT * FROM users"));
while($user=mysqli_fetch_array($users))
{
$user['email']; $user['pass'];
}
现在的问题是,我必须将包含相应数据的所有行插入到下面的数组中。这怎么可能。行将一个接一个地插入,可能就像单行注解的行一样。和非评论的是我想要的实际数据。
$user_password = array(
'username2' => 'password2',
/* You can have one or more*/ 'login'=>'password',
// $user['email'] => $user['pass'],
)
我做了一些事情,目前的状态是
$con = mysqli_connect(YOURLS_DB_HOST,YOURLS_DB_USER,YOURLS_DB_PASS);
mysqli_select_db($con,YOURLS_DB_NAME);
$users=mysqli_fetch_assoc(mysqli_query($con,"SELECT email, pass FROM users"));
while ($row = mysqli_fetch_assoc($users)) {
$email = $row['email'];
$pass = $row['pass'];
$user_pass3[] = array(
$email => $pass,
'hguhfg'=> 'nhgudfhg',
);
}
$yourls_user_passwords = $user_pass3;
//print_r($user_pass4);
/*output Array ( [0] => Array ( [test@example.com] => test [hguhfg] => nhgudfhg ) [1] => Array ( [demo@example.com] => demo [hguhfg] => nhgudfhg ) ) but disired output is Array ( [test@example.com] => test [hguhfg] => nhgudfhg [demo@example.com] => demo); */
4条答案
按热度按时间jvlzgdj91#
听了你的建议,我已经完成了计划。谢谢大家。给我们完美的密码。
hpxqektj2#
lzfw57am3#
如果您只需要登录名和密码:
neekobn84#
这个
[]
变量上的符号使其成为动态数组。所以不要使用array()
之后。如果愿意,也可以在括号内传递唯一的键。此外,您还将执行双重获取,并在数组上获取数据,该数组应失败,而不是:
你应该分配
query
返回$users
:最后一点注意,密码不应以纯文本形式存储。看到了吗https://security.stackexchange.com/questions/120540/why-shouldnt-i-store-passwords-in-plaintext