0

I am trying to convert an old mysql_ code into mysqli_ renaming all to mysqli_ doesn't work, I keep getting "Warning: mysqli_query() expects at least 2 parameters, 1 given in" and "Warning: mysqli_error() expects parameter 1 to be mysqli, string given in" could anyone help me on this on how can I convert the code below to work. I can't find an easy to understand tutorial.

function TicketFetcher(){
  $ticketsSQl = "SELECT tickets FROM tickets";
  $ticketsResult = mysqli_query($ticketsSQl) or die("Failed sql is " . 
  $ticketsSQl . "<br>Invalid query: " . mysqli_error());
  $tickets = mysqli_fetch_array($ticketsResult);
  $tickets = $tickets[0];

return $tickets;

}

user2794024
  • 39
  • 1
  • 8
  • 2
    Possible duplicate of [mysqli\_query expects at least 2 parameters](https://stackoverflow.com/questions/8073278/mysqli-query-expects-at-least-2-parameters) – Raymond Nijland Jul 11 '17 at 10:12
  • In short: you need to pass database connection handle (as returned by `mysqli_connect()`) as the first parameter to many `mysqli_*` functions (mainly to `mysqli_select_db` and `mysqli_query`). – Jirka Hrazdil Jul 11 '17 at 10:12
  • Stackoverflow is not about finding easy tutorials for you..a link the the manual should help you http://php.net/manual/en/mysqli.query.php there are easy examples on how to use mysqli_query – Raymond Nijland Jul 11 '17 at 10:14

1 Answers1

0

Because in MySQLi functions we have to pass the connection information in functions
like this

mysqli_query($conn,$ticketsSQl);    
$conn =(host,username,password,dbname); 
Bibhudatta Sahoo
  • 4,808
  • 2
  • 27
  • 51