MySQLi -
BleverCastard - 25.03.2015
I'm stumped. Can't figure this out, looked on ****** for about 45 minutes and can't find anything matching this.
For some reason, putting my query in a while loop still doesn't want to fetch.
PHP код:
$query = "SELECT * FROM `users` WHERE `username` = '$username' AND `password` = '$password'";
$run = mysqli_query($con, $query);
$check = mysqli_num_rows($run);
while($row = mysqli_fetch_assoc($run)) {
$activation = $row['activate'];
}
Re: MySQLi -
Kaperstone - 25.03.2015
PHP код:
if($run = mysqli_query($con, "SELECT * FROM `users` WHERE `username` = '$username' AND `password` = '$password'")) {
if(mysqli_num_rows($run)) {
while($row = mysqli_fetch_assoc($run)) {
$activation[] = $row['activate'];
}
}else{
echo "no rows";
}
}else{
echo "query error";
}
I guess you're trying to get data from multiple rows, then you will need to add [] at the end, so it will use the last free slot.
Re: MySQLi -
Vince - 25.03.2015
I'm pretty sure you need to specify the "link" parameter if you use procedural style. That's why I prefer object notation.
PHP код:
$db = new mysqli($host, $user, $pass, $db);
if($result = $db->query(...))
{
while($row = $result->fetch_assoc())
{
/* ... */
}
}
// etc
Re: MySQLi -
BleverCastard - 25.03.2015
Quote:
Originally Posted by Kaperstone
PHP код:
if($run = mysqli_query($con, "SELECT * FROM `users` WHERE `username` = '$username' AND `password` = '$password'")) {
if(mysqli_num_rows($run)) {
while($row = mysqli_fetch_assoc($run)) {
$activation[] = $row['activate'];
}
}else{
echo "no rows";
}
}else{
echo "query error";
}
I guess you're trying to get data from multiple rows, then you will need to add [] at the end, so it will use the last free slot.
|
Comes back as "Array"
Quote:
Originally Posted by Vince
I'm pretty sure you need to specify the "link" parameter if you use procedural style. That's why I prefer object notation.
PHP код:
$db = new mysqli($host, $user, $pass, $db);
if($result = $db->query(...))
{
while($row = $result->fetch_assoc())
{
/* ... */
}
}
// etc
|
I can't get use to that :/
Re: MySQLi -
Misiur - 25.03.2015
I really really hope you are escaping your variables (and the reason why you aren't using PDO and placeholders is another mystery). Anyway, just use var_dump($row) to see what lies inside that variable.
Re: MySQLi -
Kaperstone - 25.03.2015
Quote:
Originally Posted by BleverCastard
Comes back as "Array"
|
Because it makes the array multi-dimesional, if it returns "Arrays" means you need to specify the dimension.
use print_r to see what fish you captured
EDIT: if you're expecting a single line/row result then:
PHP код:
if($run = mysqli_query($con, "SELECT * FROM `users` WHERE `username` = '$username' AND `password` = '$password'")) {
if(mysqli_num_rows($run)) {
$row = mysqli_fetch_assoc($run);
$activation = $row['activate'];
}else{
echo "no rows";
}
}else{
echo "query error";
}
Re: MySQLi -
BleverCastard - 25.03.2015
Quote:
Originally Posted by Misiur
I really really hope you are escaping your variables (and the reason why you aren't using PDO and placeholders is another mystery). Anyway, just use var_dump($row) to see what lies inside that variable.
|
I code the way I code. And I am.
Quote:
Originally Posted by Kaperstone
Because it makes the array multi-dimesional, if it returns "Arrays" means you need to specify the dimension.
use print_r to see what fish you captured
EDIT: if you're expecting a single line/row result then:
PHP код:
if($run = mysqli_query($con, "SELECT * FROM `users` WHERE `username` = '$username' AND `password` = '$password'")) {
if(mysqli_num_rows($run)) {
$row = mysqli_fetch_assoc($run);
$activation = $row['activate'];
}else{
echo "no rows";
}
}else{
echo "query error";
}
|
I want multiple, I was just using it as an example.
Edit:
Nothing is being printed.
Edit2:
I did var_dump and it grabbed everything.
SOLVED.
Re: MySQLi -
Misiur - 25.03.2015
http://www.phptherightway.com/#mysql_extension
Re: MySQLi -
BleverCastard - 25.03.2015
Quote:
Originally Posted by Misiur
|
Like I said above, I'll code the way I want too. I don't want to use PDO. I'll use MySQLi because I feel more comfortable with it!
And I'm not using MySQL.
Re: MySQLi -
Michael@Belgium - 28.03.2015
Quote:
Originally Posted by Misiur
I really really hope you are escaping your variables (and the reason why you aren't using PDO and placeholders is another mystery). Anyway, just use var_dump($row) to see what lies inside that variable.
|
Quote:
Originally Posted by Misiur
|
What are you trying to do ? Everyone has his own way of choosing stuff - And the website you linked says
Quote:
so the best option is to replace mysql usage with mysqli or PDO
|
He's using mysqli, so what ?