There is such a simple function.

function smiles($t) { $querysmiles = $mysqli->query("SELECT * FROM `smiles` ORDER BY `id` ASC"); while($rowsmiles = mysqli_fetch_array($querysmiles)) { $code[] = $rowsmiles['code']; $smile_url[] = '<img src="'.$home.'/system/smiles/'.$rowsmiles['smile_url'].'" alt="smile" title="'.$rowsmiles['smile_url'].'" />'; } $t = str_replace($code, $smile_url, $t); return $t; } 

When using it, an error occurs. Fatal error: Call to a member function query () on a non-object in

Swears at the line

  $querysmiles = $mysqli->query("SELECT * FROM `smiles` ORDER BY `id` ASC"); 

In theory, everything is right there.

    2 answers 2

    In general, I solved the problem by adding global $ mysqli to the function;

    • Read about IoC. - Oleg Arkhipov

    if you use mysqli, then it's better to just mysqli_query

    • So by the way does not work at all. - vitagame
    • How it may not work if there are two options: Object-oriented style and Procedural style. php.net/manual/en/mysqli.query.php - Arc
    • what is better? - zb '
    • no need to mess around. You added something to make it work. Procedural style does not require it. It is simple, allows you to do without objects. - Arc
    • @Arc I did not add anything :) - zb '