PHP和MySQL连接问题 [英] PHP and MySQL Connection Problem
本文介绍了PHP和MySQL连接问题的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我正在尝试通过PHP脚本连接MySQL数据库,但没有发生任何事情成功的消息根本没有打印,我的连接代码如下:
config.php 文件:
I am trying to connect MySQL database via PHP Script but nothing is happening the conncetion Successful message is not printing at all, my code for connection is follows:
config.php file:
<?php
define("DB_HOST","localhost:81");
define("DB_USER","root");
define("DB_PASSWORD,"sandeep");
define("DB_DATABASE","android_api");
?>
DB_Connect 文件:
DB_Connect file:
<?php
class DB_Connect {
// constructor
function __construct() {
}
// destructor
function __destruct() {
// $this->close();
}
// Connecting to database
public function connect() {
require_once 'config.php';
// connecting to mysql
$con = mysql_connect(DB_HOST, DB_USER, DB_PASSWORD);
// selecting database
mysql_select_db(DB_DATABASE);
// return database handler
return $con;
}
// Closing database connection
public function close() {
mysql_close();
}
}
?>
推荐答案
this - >关闭();
}
//连接数据库
public function connect(){
require_once'config.php';
//连接到mysql
this->close(); } // Connecting to database public function connect() { require_once 'config.php'; // connecting to mysql
con = mysql_connect(DB_HOST,DB_USER,DB_PASSWORD);
//选择数据库
mysql_select_db(DB_DATABASE);
//返回数据库处理程序
return
con = mysql_connect(DB_HOST, DB_USER, DB_PASSWORD); // selecting database mysql_select_db(DB_DATABASE); // return database handler return
con;
}
//关闭数据库连接
public function close(){
mysql_close();
}
}
?>
con; } // Closing database connection public function close() { mysql_close(); } } ?>
这篇关于PHP和MySQL连接问题的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文