Why can I log on but cannot connect to the database?

Source: Internet
Author: User
Why can I log on but cannot connect to the database ;? Phpinclude ("sqlInfo. inc "); $ connect & nbsp ;=& nbsp; mysqli_connect ($ host, & nbsp; $ account, & nbsp; $ password) or & nbsp; why can I log on to die ("Couldn't & nbsp; connect, but cannot connect to the database?
 include("sqlInfo.inc");
$connect = mysqli_connect($host, $account, $password)
or die("Couldn't connect to server");
$db = mysqli_select_db($connect,"world")
or die("Couldn't connect to database");
$sql = "SELECT * FROM city";
$result = mysql_query($sql)
or die("Couldn't query to table".mysql_error());
while($row = mysql_fetch_array($result))
{
foreach($row as $value)
{
echo "$value
";
}
}
?>


Error message: Couldn't query to table Access denied for user 'odbc '@ 'localhost' (using password: NO)
------ Solution --------------------
Use mysqli to use all mysqli functions
So the next two ....
Echo $ value;
Not echo "$ value ";
What's the significance of using mysqli extension library like this?
------ Solution --------------------
Mysqli_connect () missing the fourth parameter (database name)

The mysql_query and mysql_fetch_array are not consistent with those saved previously.
------ Solution --------------------
Use mysqli to connect to the database
Use mysql_query to operate the database ....

How has someone made this mistake recently? Is it taught by the same teacher?

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.