在非对象中调用成员函数fetch_assoc()。错误的PHP代码?

时间:2016-03-28 20:34:14

标签: php mysql sql

import <Google/Analytics.h>

我收到错误:

  

在...

中的非对象上调用成员函数fetch_assoc()

1 个答案:

答案 0 :(得分:1)

<?php
$conn = new mysqli($servername, $username, $password, $dbname);

/* check connection */
if ($conn->connect_errno) {
  printf("Connect failed: %s\n", $conn->connect_error);
  exit();
}

$sql = "SELECT Nr FROM AlleTransaktionen1";

$my_money = 0;

if ($result = $conn->query($sql)) {

  /* fetch associative array */
  while ($row = $result->fetch_assoc()) {
    printf ($row["Nr"]);
}

/* free result set */
  $result->free();
}

/* close connection */
  $mysqli->close();
?>