简体   繁体   English

将旧的mysql_代码转换为mysqli_查询

[英]Convert an old mysql_ code into mysqli_ queries

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. 我正在尝试将旧的mysql_代码转换为mysqli_,将其全部重命名为mysqli_不起作用,我不断收到“警告:mysqli_query()至少应输入2个参数,并输入1个”“警告:mysqli_error()期望将参数1转换为是mysqli,输入的字符串是“任何人都可以帮助我解决以下代码的问题。” 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;

} }

Because in MySQLi functions we have to pass the connection information in functions 因为在MySQLi函数中,我们必须在函数中传递连接信息
like this 像这样

mysqli_query($conn,$ticketsSQl);    
$conn =(host,username,password,dbname); 

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM