-3

I get the following errors on the below php, this is used to get chart information from the mysql database. Appreciate the help

Warning: mysqli_query() expects at least 2 parameters, 1 given in C:\wamp\www\test\getuser.php on line 5 Warning: mysqli_select_db() expects exactly 2 parameters, 1 given in C:\wamp\www\test\getuser.php on line 6 Call to undefined function mysqli_fetch() in C:\wamp\www\dada\getuser.php on line 18

PHP,

<?php
header("Content-type=text/json;charset=UTF-8");

$aVar = mysqli_connect('localhost', 'root', '123');
mysqli_query("set names utf-8");
mysqli_select_db("test");
$resultset = mysqli_query($aVar,"SELECT name, age FROM echartsuser");

$data = array();

class User{
public $username;
public $age;
}

while($row = mysqli_fetch_assoc($resultset);
$user = new User();
$user->username = $row['name'];
$user->age = $row['age'];
$data[] = $user;
}
mysqli_close();

echo json_encode($data);

?>
Rai Vu
  • 1,595
  • 1
  • 20
  • 30

1 Answers1

0
mysqli_query("set names utf-8");

In the above line you have pass the connection object.

mysqli_query($aVar,"set names utf-8");

Use the above line.

Same in the line number 6 you have to pass the object of connection:

mysqli_select_db($aVar, "test");
Code Lღver
  • 15,573
  • 16
  • 56
  • 75