A
A
Alexander2012-07-10 22:04:41
PHP
Alexander, 2012-07-10 22:04:41

How to show mysqli_query result?

Hello.

There is php 5.4

There was such a problem, you need to show the result of mysqli_query and UPDATE.

There was code in PHP 5.2:

$result = $db->query("UPDATE `table` SET `tb1`='$test' ");
 
if ($result == TRUE) {echo "Обновлено";} else {echo "Не обновлено";}



but on 5.4 it doesn't work.

Please tell me how to adapt this code to PHP 5.4

PS The query function is here:

    function query($query, $show_error=true)
    {
        $time_before = $this->get_real_time();
 
        if(!$this->db_id) $this->connect(DBUSER, DBPASS, DBNAME, DBHOST);
        
        if(!($this->query_id = mysqli_query($this->db_id, $query) )) {
 
            $this->mysql_error = mysqli_error($this->db_id);
            $this->mysql_error_num = mysqli_errno($this->db_id);
 
            if($show_error) {
                $this->display_error($this->mysql_error, $this->mysql_error_num, $query);
            }
        }
            
        $this->MySQL_time_taken += $this->get_real_time() - $time_before;
        
             'num'   => (count($this->query_list) + 1));
        
        $this->query_num ++;
 
        return $this->query_id;
    }



PSS Strongly do not scold for the code, I'm just starting to learn PHP and MySQLi

Answer the question

In order to leave comments, you need to log in

5 answer(s)
S
sdevalex, 2012-07-10
@sdevalex

Use PDO. mysqli_* functions are a thing of the past.

P
Placido, 2012-07-10
@Placido

In an amicable way, for a start it is necessary to result the text of an error. But here at least one mistake is visible to the naked eye. I’ll hint: where did it come from and what does this line of code mean:

'num'   => (count($this->query_list) + 1));

E
EugeneOZ, 2012-07-11
@EugeneOZ

What have you already tried to do? “Here is the code, fix it for me” is not very polite.

T
tnz, 2012-07-11
@tnz

Well, if that's the case, then replace

if ($result == TRUE)
on the
if ($result)

W
winbackgo, 2012-07-11
@winbackgo

php.net/manual/ru/mysqli.affected-rows.php A $result will always be true because the function returns the connection ID, you need mysqli_affected_rows($result ).

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question