转换主连接错误

时间:2017-10-12 15:06:00

标签: php mysql

运行代码时出现以下错误:

  

注意:使用未定义的常量newdb - 在行 9 C:\ xampp \ htdocs \ cj \ include \ conn.php 中假定为'newdb'
未选择数据库

以下用于连接我在conn.php文件中使用的代码 ,

<?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>";

?>

如何解决?

1 个答案:

答案 0 :(得分:0)

这只是需要考虑的事项:尝试在没有["___mysqli_ston"]

的情况下使用它
  

实施例

<?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();
}

?>

只是一个不同的简单方法的例子。

对于转换器

  

实施例

<?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));  
?>