dtrpv60860
2017-03-10 08:27
浏览 51
已采纳

连接到xampp数据库

Am trying to connect to a xampp server but its not working this is my code:

session_start();

define('DB_NAME', 'login');
define('DB_USER', 'root');
define('DB_PASSWORD', '');
define('DB_HOST', 'localhost');

$link = mysql_connect(DB_HOST, DB_USER, DB_PASSWORD);

if ($link) {
    die('Failed to connect: ' . mysql_error());
}
$db_select = mysql_select_db(DBNAME, $link);
if (!$db_select) {
    die('Failed to connect:' . DBNAME . ':' . mysql_error());
}

图片转代码服务由CSDN问答提供 功能建议

我试图连接到xampp服务器但它无法正常工作这是我的代码: < / p>

  session_start(); 
 
define('DB_NAME','login'); 
define('DB_USER','root'); 
define('DB_PASSWORD','');  
define('DB_HOST','localhost'); 
 
 $ link = mysql_connect(DB_HOST,DB_USER,DB_PASSWORD); 
 
if($ link){
 die('连接失败:'。mysql_error(  ); 
} 
 $ db_select = mysql_select_db(DBNAME,$ link); 
if(!$ db_select){
 die('连接失败:'。DBNAME。':'。mysql_error()); \  n} 
   
 
  • 点赞
  • 写回答
  • 关注问题
  • 收藏
  • 邀请回答

2条回答 默认 最新

  • doulan9419 2017-03-10 08:31
    已采纳

    mysql is no longer usable. use mysqli and it will work fine

    If you want to know more about it visit https://www.w3schools.com/php/func_mysqli_query.asp

    点赞 打赏 评论
  • donglu7286 2017-03-10 08:40

    If you can solve the problem, try it with this sentence and you will see the error faster.

     <?php $servername = "localhost"; $username = "username"; $password = "password";
    
    try {
        $conn = new PDO("mysql:host=$servername;dbname=myDB", $username, $password);
        // set the PDO error mode to exception
        $conn->setAttribute(PDO::ATTR_ERRMODE, PDO::ERRMODE_EXCEPTION);
        echo "Connected successfully";
        } catch(PDOException $e)
        {
        echo "Connection failed: " . $e->getMessage();
        } ?>
    
    点赞 打赏 评论

相关推荐 更多相似问题