【发布时间】:2016-07-14 17:49:50
【问题描述】:
目前我的代码是用来连接我的数据库的。
<?php
/**
* A class file to connect to database
*/
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();
}
}
?>
db_config.php 是
<?php
define('DB_USER', "root"); // db user
define('DB_PASSWORD', ""); // db password (mention your db password here)
define('DB_DATABASE', "leading10"); // database name
define('DB_SERVER', "localhost"); // db server
?>
在某处使用上述代码时,它会显示使用 mysqli 或 PDO 的警告 我关注了许多 stackoverflow 问题,但仍然无法成功。 我知道的一种方法是在 mysql_connect() 之前使用 @ 符号,但将来可能无法使用。 任何帮助表示赞赏
【问题讨论】:
标签: php mysql mysqli pdo mysql-connect