Fatal error: Call to a member function in: Z: \ home \ newmy \ www \ core \ modules \ portfolio \ portfolio.php on line 17 on line 17:

$ row = $ sql-> fetch_array (MYSQLI_ASSOC);

Here is the whole code:

$sql = $db->prepare("SELECT * FROM projects WHERE id = ?") or die ("Ошибка #327387239"); $sql->bind_param("i", $id); $id = $routes[2]; $sql->execute() or die("Предупреждение о неудачном запросе"); $row = $sql->get_result(); if ($row->num_rows){ $row = $sql->fetch_array(MYSQLI_ASSOC); echo $row['title']; 
  • one
    And fetch_array is whose method? mysqli_stmt - no, not really. mysqli_result - yes. There was something about mysqli_query (), mysqli_store_result () or mysqli_use_result (). And about execute it is written: If UPDATE, DELETE, or INSERT queries are executed, then the number of modified rows can be determined by the function mysqli_stmt_affected_rows (). If the query returns a result set, you can use the mysqli_stmt_fetch () function to extract data from it. Maybe true? - alexlz

2 answers 2

 $row = $sql->get_result(); // что тут должно выводиться-то? для чего тут get_result? Убери эту строчку и все. должно помочь. if ($row->num_rows){ $row = $sql->fetch_array(MYSQLI_ASSOC); echo $row['title']; 
  • get_result - we get the result from the request, then the condition is whether there are articles, without that line in any way! - Pavel Dura
  • 2
    Then why $sql->fetch_array() and not $row->fetch_array() ? - alexlz
  • I first did this, the current does not output anything at all, here is the var_dump object (mysqli_stmt) # 2 (9) {["affected_rows"] => int (1) ["insert_id"] => int (0) ["num_rows"] => int (0) ["param_count"] => int (1) ["field_count"] => int (10) ["errno"] => int (0) ["error"] => string (0) "" ["sqlstate"] => string (5) "00000" ["id"] => int (1)} - Pavel Dura
  • Yes, php is a diagnosis. get_result didn't work for me. Try $sql->fetch - it worked for me. php 5.3.14. But he needs bind_result - alexlz

See what you have in $sql . It swears that $sql not an object for you. Most likely some kind of error occurs.

  • My MySQLI is what the var dump says: object (mysqli_stmt) # 2 (9) {["affected_rows"] => int (1) ["insert_id"] => int (0) ["num_rows"] => int ( 0) ["param_count"] => int (1) ["field_count"] => int (10) ["errno"] => int (0) ["error"] => string (0) "" [" sqlstate "] => string (5)" 00000 "[" id "] => int (1)} - Pavel Dura