我的数据库名为'login'。这是我的login.php / register.php文件(保存到htdocs)中使用的php语句,它应该建立一个数据库连接。
$this->db_connection = new mysqli(DB_HOST, DB_USER, DB_PASS, DB_NAME);
我想确保连接成功,所以我假设我必须更改这些
(DB_HOST, DB_USER, DB_PASS, DB_NAME)
到这个
('localhost', 'username', 'password', 'login');
唯一的问题是我被命名约定所取代,即'localhost','root','root'等。这是我的mamp启动页面上列出的内容
Host localhost
Port 3306
User root
Password root
Socket /Applications/MAMP/tmp/mysql/mysql.sock
这些是我的mamp启动页面上列出的使用信息
的示例$user = 'root';
$password = 'root';
$db = 'inventory'; //what is this?
$host = 'localhost';
$port = 3306;
$link = mysql_connect(
"$host:$port",
$user,
$password
);
$db_selected = mysql_select_db(
$db,
$link
);
这是否意味着我应该将login / register.php配置为;
$this->db_connection = new mysqli ('localhost', 'username', 'password', 'login');
还是以这种方式完成?
$this->db_connection = new mysqli ('localhost', 'root', 'root', 'login');
这是在配置文件db.php中,它应该保存在我的应用程序的同一目录中;
<?php
define("DB_HOST", "127.0.0.1");
define("DB_NAME", "login");
define("DB_USER", "root");
define("DB_PASS", "mysql");
?>
我以为
'DB_HOST',
'DB_NAME',
'DB_USER',
'DB_PASS'
是要编辑和更改的空间填充程序,但这是否意味着我可以保留原始行;
$this->db_connection = new mysqli(DB_HOST, DB_USER, DB_PASS, DB_NAME);
如果我将db.php保存在同一目录中?或者,我是否应该编辑它以阅读类似的内容;
define("DB_HOST", "127.0.0.1"); **** define("DB_HOST", "localhost");
define("DB_NAME", "login"); **** define("DB_NAME", "login");
define("DB_USER", "root"); **** define("DB_USER", "root");
define("DB_PASS", "mysql"); **** define("DB_PASS", "root"); //i.e. my password has never been mysql
我也想知道这条线是否会作为一个可靠的常数;
grant all privileges on login.* to 'root'@'localhost' identified by 'root'; //or should it be identified by 'password'?