MySQLi
#1

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'];
        } 
Reply
#2

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.
Reply
#3

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 
Reply
#4

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 :/
Reply
#5

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.
Reply
#6

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"

Reply
#7

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.
Reply
#8

http://www.phptherightway.com/#mysql_extension
Reply
#9

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.
Reply
#10

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 ?
Reply


Forum Jump:


Users browsing this thread: 3 Guest(s)