T
T
Taras Serevann2015-03-31 11:22:37
PHP
Taras Serevann, 2015-03-31 11:22:37

Alternative to get_result() in mysqli?

Hello!
There is the following code:

$query = $this->DB->prepare("SELECT * FROM photos WHERE id = ? AND authkey = ?");
      $query->bind_param('is', $_COOKIE['photoid'], $_COOKIE['authkey']);
      $query->execute();
      $result = $query->get_result();
    
      if ($result->num_rows != 0) {
        // user exist
        $this->userLogged = true;
        $this->userData = $result->fetch_assoc();
        return $this->userData;
      } else {
        return false;
      }

It is used to fetch user data as an associative array and store it in a variable for later access.
But there was a problem: my host does not have mysqlnd installed, so there is no way to use get_result().
Please advise an alternative to get_result() that does not require mysqlnd or tell me how to implement the same code, but without using get_result()

Answer the question

In order to leave comments, you need to log in

1 answer(s)
F
FanatPHP, 2015-03-31
@Taras_Serevann

1. The most convenient alternative is safemysql , the code will be halved

$sql = "SELECT * FROM photos WHERE id = ?s AND authkey = ?s";
$row = $db->getRow($sql, $_COOKIE['photoid'], $_COOKIE['authkey']);
if ($row)
{
        $this->userLogged = true;
        $this->userData = $row;
        return TRUE;
}

But using this library requires some development experience and for this reason it is not suitable for everyone.
2. A less convenient alternative is PDO. the "no time to rewrite" argument is ridiculous.
Firstly, it was necessary to think earlier, and not shit-code mysqli functions in the application code, instead of wrapping them in a helper class.
Secondly, do not think that the work on the site is over. She's just getting started. Considering that in PDO one line does what is needed in mysqli 10, then on the contrary, there will be huge savings during the transition.
3. The easiest solution to the problem is to change the host. But in this case, all hellish govnokod will remain in place.
4. Well, the most crooked option is to add more hell and shit code with bind_result ()

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question