Warning: mysqli_select_db() expects exactly 2 parameters, 1 given in

后端 未结 3 1831
时光取名叫无心
时光取名叫无心 2020-12-22 14:23

im a beginner and also a diploma student... i have created database using localhost... im having problem viewing my database... please help me... i hope u can help me with a

相关标签:
3条回答
  • 2020-12-22 15:03
    In Mysqli you have to pass two parameters. 
    1) sql Connection
    2) sql query
    example : 
      <?php
    // Connect to server and select database.
       $con=mysqli_connect("$host", "$username",        
      "$password","$db_name")or         die("cannot connect server "); 
       $name="abc";
       $email="abc@gmail.com";
       $sql="INSERT INTO $tbl_name(name, email)VALUES('$name','$email')";
       $result=mysqli_query($con,$sql);
       mysqli_close($con);
    ?>
    
    0 讨论(0)
  • 2020-12-22 15:04

    If you check the php manual here: http://php.net/manual/fr/mysqli.select-db.php

    You will see the function mysqli_select_db take two params in input.

    bool mysqli_select_db ( mysqli $link , string $dbname )

    So you should have

    // Connect to server and select databse.
    $conn = mysqli_connect($host, $username, $password) or die("cannot connect"); 
    mysqli_select_db($conn, $db_name) or die("cannot select DB");
    
    0 讨论(0)
  • 2020-12-22 15:05

    You dont need a separate function for select database in mysqli function,

    The below method is more than enough to connect and select the database,

     // Connect to server and select databse.
        $conn = mysqli_connect($host, $username, $password,$db_name)or die("cannot connect"); 
    

    doc: http://php.net/manual/en/mysqli.select-db.php

    0 讨论(0)
提交回复
热议问题