运行代码时出现以下错误:
注意:使用未定义的常量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>";
?>
如何解决?
答案 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));
?>