-1

I got following error when i run code:

Notice: Use of undefined constant newdb - assumed 'newdb' in C:\xampp\htdocs\cj\include\conn.php on line 9
No database selected

The following code for connecting i am using in conn.php file ,

<?php
    $lusername = "root";
    $lpassword = "";
    $lhostname = "localhost";
    // connection to the database
    $dbhandle = ($GLOBALS["___mysqli_ston"] = mysqli_connect($lhostname, $lusername, $lpassword)) or die("Unable to connect to mysql");

    mysqli_select_db($GLOBALS["___mysqli_ston"], newdb) or die("Unable to connect to mysql");
    // echo "Connected to mysql<br>";

?>

how to fix it?

1 Answers1

0

This is just something to consider: try using it without ["___mysqli_ston"]

Example

<?php 


 $servername = "localhost";
 $username = "";
 $password = "yourpass";
 $dbname = "yourDBname";


// Create connection
 $conn = new mysqli($servername, $username, $password, $dbname);
// Read special character sets
 $conn->set_charset("utf8");

// Check connection
 if (mysqli_connect_errno()) {
 printf("Connect failed: %s\n", mysqli_connect_error());
 exit();
}

?>

Just an example of different easier approach all up to you.

For the converter

Example

<?php  
  $servername = "localhost" ;  
  $username = "root"; 
  $pass = "";  
  $con = ($GLOBALS["___mysqli_ston"] = mysqli_connect($servername, $username, $pass)) or die("Problem occur in connection");  
  $db = ((bool)mysqli_query($con, "USE " . info));  
?>
Ylama
  • 2,449
  • 2
  • 25
  • 50
  • I use master converter to convert my mysql code to mysqli and it uses "___mysqli_ston" in all of the files, so must have to use it – user3355035 Oct 12 '17 at 15:58
  • orait, the my only help would be check this out -- [link](https://dzone.com/articles/convert-mysql-to-mysqli) , hope it puts you on the right track! – Ylama Oct 12 '17 at 16:05
  • ok no put the above code and with quotes now i got only following message No database selected – user3355035 Oct 12 '17 at 16:06
  • look at that link i posted in my previous comment should resolve your problem. [click me](https://dzone.com/articles/convert-mysql-to-mysqli) – Ylama Oct 12 '17 at 16:12
  • after putting above 2nd code same error message No database selected – user3355035 Oct 12 '17 at 16:17