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

警告: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 delta降尺度计算的一些细节,有偿
  • ¥15 Arduino红外遥控代码有问题
  • ¥15 数值计算离散正交多项式
  • ¥30 数值计算均差系数编程
  • ¥15 redis-full-check比较 两个集群的数据出错
  • ¥15 Matlab编程问题
  • ¥15 训练的多模态特征融合模型准确度很低怎么办
  • ¥15 kylin启动报错log4j类冲突
  • ¥15 超声波模块测距控制点灯,灯的闪烁很不稳定,经过调试发现测的距离偏大
  • ¥15 import arcpy出现importing _arcgisscripting 找不到相关程序