简体   繁体   English

与MySQL的MySQL错误连接失败

[英]MySQL error connection to mysql failed

The includes are of SQL.php, the below code is SQL.php 包括的是SQL.php,下面的代码是SQL.php

Notice: Undefined index: myusername in C:\\xampp1\\htdocs\\cp\\global\\class\\user.php on line 3 注意:未定义的索引:第3行的C:\\ xampp1 \\ htdocs \\ cp \\ global \\ class \\ user.php中的myusername

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 致命错误:未捕获错误:调用C:\\ xampp1 \\ htdocs \\ cp \\ global \\ class \\ SQL.php:29中未定义的函数mysql_connect()堆栈跟踪:#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}放在C:\\ xampp1 \\ htdocs \\ cp \\ global \\ class \\ SQL.php上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());
?>

Use mysqli extension.Because mysql extension is deprecated. 使用mysqli扩展名。因为不推荐使用mysql扩展名。

$connection = mysqli_connect(HOST, USRNM, PSWD) or die('Could not connect: ' . mysqli_connect_error()); //This line
mysqli_select_db($connection,DBNM);
?>

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM