Home >Backend Development >PHP Tutorial > 为啥可以登录,但无法连接数据库

为啥可以登录,但无法连接数据库

WBOY
WBOYOriginal
2016-06-13 13:00:25857browse

为什么可以登录,但无法连接数据库

<?php<br />
include("sqlInfo.inc");<br />
$connect = mysqli_connect($host, $account, $password)<br />
	or die("Couldn't connect to server");<br />
$db = mysqli_select_db($connect,"world")<br />
	or die("Couldn't connect to database");<br />
$sql = "SELECT * FROM city";<br />
$result = mysql_query($sql)<br />
	or die("Couldn't query to table".mysql_error());<br />
while($row = mysql_fetch_array($result))<br />
{<br />
	foreach($row as $value)<br />
	{<br />
		echo "$value<br>";<br />
	}<br />
}<br />
?>


提示错误为:Couldn't query to table  Access denied for user 'ODBC'@'localhost' (using password: NO)
------解决方案--------------------
用mysqli就全用mysqli函数
所以之后的两个。。。。
还有echo $value;
不是echo "$value";
另外你这样用mysqli扩展库有什么意义
------解决方案--------------------
mysqli_connect() 少了第四个参数(库名) 

后面的 mysql_query 和 mysql_fetch_array 也没有和前面保存一致。
------解决方案--------------------
用的mysqli链接数据库
用的mysql_query 操作数据库....

最近怎么老有人犯这个错误?是同个老师教出来的?

Statement:
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn