[英]Can't connect database (mysql) with php files on external server
Can't connect database (mysql) with below php files from external server (godaddy).无法使用来自外部服务器(godaddy)的以下 php 文件连接数据库(mysql)。 warning : mysql_connect() []: cant't connect to mysql server on (10061) in /files/files/db.php and also from index.php `
警告:mysql_connect() []: 无法在 /files/files/db.php 和 index.php 中连接到 (10061) 上的 mysql 服务器
<?php
$conn=mysql_connect("localhost","dbusername","dbpasswd");
$db=mysql_select_db('dbname',$conn);
?>
` `
and in db_config.php并在 db_config.php
` `
<?php
define('DB_USER', "dbusername");
define('DB_PASSWORD', "dbpasswd");
define('DB_DATABASE', "dbname");
define('DB_SERVER', "server address"); // db server
$servername = "url.com";
$username = "dbusername";
$password = "dbpasswd";
$dbname = "dbname";
$conn= mysql_connect($servername,$username,$password)or die(mysql_error());
mysql_select_db('dbname',$conn);
?>
` `
and in db_connect.php并在 db_connect.php
` `
<?php
class DB_CONNECT {
// constructor
function __construct() {
// connecting to database
$this->connect();
}
// destructor
function __destruct() {
// closing db connection
$this->close();
}
/**
* Function to connect with database
*/
function connect() {
// import database connection variables
require_once __DIR__ . '/db_config.php';
// Connecting to mysql database
$con = mysql_connect(DB_SERVER, DB_USER, DB_PASSWORD) or die(mysql_error());
// Selecing database
$db = mysql_select_db(DB_DATABASE) or die(mysql_error()) or die(mysql_error());
// returing connection cursor
return $con;
}
/**
* Function to close db connection
*/
function close() {
// closing db connection
mysql_close();
}
}
?>
` `
This is not a problem of your code... This problem exists because you are trying to connect a live website with your localhost database.这不是您的代码的问题...存在此问题是因为您正尝试将实时网站与 localhost 数据库连接。 I dont know how to work it out with godaddy because I use MS azure... But I can give you a basic idea - If you want to connect a live website with a database, you will have to make a database on godaddy.
我不知道如何使用 Godaddy 解决这个问题,因为我使用的是 MS azure...但我可以给你一个基本的想法 - 如果你想将一个实时网站与数据库连接起来,你必须在 Godaddy 上创建一个数据库。 I know I answered it too late
我知道我回答得太晚了
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.