简体   繁体   English

sql无法连接到Nginx中的mysql数据库(Ubuntu 12.04)

[英]Can't sql connect to mysql database in nginx (ubuntu 12.04)

I have the following sqlconnection.php 我有以下sqlconnection.php

$mysqli = new mysqli('localhost', 'myuser', 'mypassword', 'mydb');

if ($mysqli->connect_error()) {
    die('Connect Error (' . $mysqli->connect_rror() . ') '
            . mysqli_connect_error());
}

with myuser , mypassword and mydb values being set correctly. 正确设置myusermypasswordmydb值。 Anyway, although I am able to do operations with phpmyadmin (I got that installed aswell) I can't get to connect to the database. 无论如何,尽管我可以使用phpmyadmin进行操作(我也已经安装了该程序),但我无法连接到数据库。 Any idea on why and what exactly I should put in localhost? 关于为什么以及到底应该在本地主机中放置什么的任何想法?

Just try this way~ 尝试一下〜

   $dbhost = 'localhost';
$dbuser = 'dbuser';
$dbpass = 'password';
$dbname = 'dbname';

$link = mysql_connect($dbhost, $dbuser, $dbpass);
if (!$link) {
    die('Could not connect: ' . mysql_error());
}
mysql_select_db($dbname);

if all your db information is correct, should be working 如果您所有的数据库信息都正确,则应该可以正常工作

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM