我刚开始使用Mysql
和php
,而且我已经将truoble连接到我的数据库。我使用的是phpmyadmin
,但它与000webhost
一起使用。我用这段代码得到了这两条错误消息。
警告:mysqli_connect():( HY000 / 1045):ProxySQL错误:用户访问被拒绝' 123456' @' 2a02:4780:bad:f00d :: 3' (使用密码:YES)在第8行的/storage/h11/920/1783920/public_html/DB.php
警告:mysqli_query()要求参数1为mysqli,第14行的/storage/h11/920/1783920/public_html/DB.php中给出布尔值
<?php
$host='localhost';
$user='123456';
$pass='123456';
$db='id1783920_mydb';
$con=mysqli_connect($host,$user,$pass,$db);
if($con) {
echo 'connected successfully to id1783920_mydb database';
}
$sql="insert into Signup (username,password,email) values ('Matt',123456,'smis@shaw.ca')";
$query=mysqli_query($con,$sql);
if($query) {
echo 'data inserted successfully';
}
?>
任何人都可以帮忙吗?
答案 0 :(得分:0)
您确定您的用户名和密码是否正确?
您必须从000webhost数据库管理面板控制用户名和密码。
您可以使用此db类来建立数据库连接。
class db{
public $server;
public $user;
public $password;
public $database;
/**
* @return mixed
*/
public function getServer(){
return $this->server;
}
/**
* @param mixed $server
*/
public function setServer($server){
$this->server = $server;
}
/**
* @return mixed
*/
public function getUser(){
return $this->user;
}
/**
* @param mixed $user
*/
public function setUser($user){
$this->user = $user;
}
/**
* @return mixed
*/
public function getPassword(){
return $this->password;
}
/**
* @param mixed $password
*/
public function setPassword($password){
$this->password = $password;
}
/**
* @return mixed
*/
public function getDatabase(){
return $this->database;
}
/**
* @param mixed $database
*/
public function setDatabase($database){
$this->database = $database;
}
public function open(){
$conn = mysqli_connect($this->server , $this->user , $this->password , $this->database) or die("Sunucuya baglanilamadi.");
mysqli_query($conn , "SET NAMES utf8");
mysqli_query($conn , "SET CHARACTER SET utf8");
mysqli_query($conn , "SET COLLATION_CONNECTION='utf8_general_ci'");
return $conn;
}
public function getRecordCount($sql){
$query = $this->runSql($sql);
return mysqli_num_rows($query);
}
public function runSql($sql){
$conn = $this->open();
$query = mysqli_query($conn, $sql);
if($query)
return $query;
}
}
此数据库连接属性为json文件。
{
"server" : "localhost",
"database" : "id1762350_blog_sitem", // your database name
"username" : "id1762350_mehfatitem", // your username
"password" : "your_password" // your password
}
我希望这个解释会对你有帮助。