douyan6871
douyan6871
2017-01-01 06:57

MySQL错误连接到mysql失败

已采纳

The includes are of SQL.php, the below code is SQL.php

Notice: Undefined index: myusername in C:\xampp1\htdocs\cp\global\class\user.php on line 3

Fatal error: Uncaught Error: Call to undefined function mysql_connect() in C:\xampp1\htdocs\cp\global\class\SQL.php:29 Stack trace: #0 C:\xampp1\htdocs\cp\global\class\user.php(4): require() #1 C:\xampp1\htdocs\cp\global\func.php(2): require('C:\xampp1\htdoc...') #2 C:\xampp1\htdocs\cp\index.php(2): require('C:\xampp1\htdoc...') #3 {main} thrown in C:\xampp1\htdocs\cp\global\class\SQL.php on line 29

<?php
/*$host="localhost";
$username="root";
$password="";
$host="localhost";
$username="root";
$password="";
$db_name="rgrp"*/

// Windows Box
DEFINE('HOST', 'localhost');
DEFINE('USRNM', 'root');
DEFINE('PSWD', ''); //no password, using xampp
DEFINE('DBNM', 'rgrp');

/* Linux Box
DEFINE('HOST', 'localhost');
DEFINE('USRNM', 'root');
DEFINE('PSWD', '');
DEFINE('DBNM', 'rgrp');
*/
/*
DEFINE('HOST', 'localhost');
DEFINE('USRNM', 'root');
DEFINE('PSWD', '');
DEFINE('DBNM', 'rgrp');
*/

mysql_connect(HOST, USRNM, PSWD) or die('Could not connect: ' . mysql_error()); //This line
mysql_select_db(DBNM) or die('Could not connect: ' . mysql_error());
?>
  • 点赞
  • 写回答
  • 关注问题
  • 收藏
  • 复制链接分享
  • 邀请回答

1条回答

  • dth34653 dth34653 4年前

    Use mysqli extension.Because mysql extension is deprecated.

    $connection = mysqli_connect(HOST, USRNM, PSWD) or die('Could not connect: ' . mysqli_connect_error()); //This line
    mysqli_select_db($connection,DBNM);
    ?>
    
    点赞 评论 复制链接分享

为你推荐