dongmo9996 2016-04-08 06:20
浏览 247
已采纳

警告:mysqli_select_db()需要2个参数,1个给定* 13 * [重复]

This question already has an answer here:

I'm working on a system for my school that lets the teachers post any notices they have for the day on the intranet. However I got this error when testing it out:

Warning: mysqli_select_db() expects exactly 2 parameters, 1 given in C:\Users\Matthew\Desktop\wamp64\www\my-site\viewguestbook.php on line 23.

Here is the page's code:

<?php

$host="localhost"; // Host name 
$username="root"; // Mysql username 
$password=""; // Mysql password 
$db_name="test"; // Database name 
$tbl_name="guestbook"; // Table name 

// Connect to server and select database.
mysqli_connect("$host", "$username", "$password")or die("cannot connect server "); 
mysqli_select_db("$db_name")or die("cannot select DB");
$sql="SELECT * FROM $tbl_name";
$result=mysqli_query($sql);
while($rows=mysqli_fetch_array($result)){
?>

Note: This is different to the other questions of this same name on the website as it's in a different circumstance.

</div>
  • 写回答

3条回答 默认 最新

  • douyi4297 2016-04-08 06:24
    关注

    The first parameter of mysqli_select_db() is connection object. This is the syntax :

    mysqli_select_db(connection,dbname);
    

    Change your code to:

    $con = mysqli_connect("$host", "$username", "$password")or die("cannot connect server "); 
    mysqli_select_db($con,$db_name)or die("cannot select DB");
    

    Add the connection object as first parameter in mysqli_query and mysqli_fetch_array functions too. Please refer this link for the syntax.

    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论
查看更多回答(2条)

报告相同问题?

悬赏问题

  • ¥15 单通道放大电路的工作原理
  • ¥30 YOLO检测微调结果p为1
  • ¥20 求快手直播间榜单匿名采集ID用户名简单能学会的
  • ¥15 DS18B20内部ADC模数转换器
  • ¥15 做个有关计算的小程序
  • ¥15 MPI读取tif文件无法正常给各进程分配路径
  • ¥30 关于#算法#的问题:运用EViews第九版本进行一系列计量经济学的时间数列数据回归分析预测问题 求各位帮我解答一下
  • ¥15 setInterval 页面闪烁,怎么解决
  • ¥15 如何让企业微信机器人实现消息汇总整合
  • ¥50 关于#ui#的问题:做yolov8的ui界面出现的问题