0

I have created 'hello' database using phpMyAdmin and student table. Now following code is not working, despite being completely true.

<?php

     $conn=mysqli_connect('localhost','divyang','','hello');

     $a=mysql_select_db('hello',$conn);

     echo "<br>";

      if (!$a) {
       die('Could not connect: ' . mysql_error());
        }

      $query="SELECT * FROM `student`";

        $result=mysqli_query($query,$conn);

           while($row=mysqli_fetch_array($result)){
           echo "".$row["name"]." ".$row["surname"]."<br>";
           }
          ?>

This code just gives 'could not connect' answer. It gives nothing other in return.

Francisco
  • 10,918
  • 6
  • 34
  • 45
  • you should use mysqli or PDO. You are using mysqli for most of it but I think your second line of code should look like this: $a=mysqli_select_db($conn, 'hello'); http://php.net/manual/en/mysqli.select-db.php – victor Apr 18 '17 at 19:37
  • Note: This function should only be used to change the default database for the connection. You can select the default database with 4th parameter in mysqli_connect(). – victor Apr 18 '17 at 19:37
  • Any other information like the error message returned by mysql_error()? – Walter Palladino Apr 18 '17 at 19:38

0 Answers0