The user name that PHP reads out of the file cannot be used to connect to the database

Source: Internet
Author: User
The user name that PHP reads out of the file cannot be used to connect to the database
$this->conn = mysql_connect ($this->db_host, $this->db_user, $this->db_pwd);
if (! ( $this->conn))
{
Die (' Could not connect: '. Mydsql_error (' connection error '));
}
Echo ' Connection is successful!
';
$this->db_host, $this->db_user, $this->db_pwd are taken from the. ini file, the value of the host address and password can be used, but the user name is not, if the user name is directly connected to the string MySQL will not go wrong, if the user name is removed from the file for the connection, an error will occur, as follows:
Warning:mysql_connect (): Access denied for user ' noco ' @ ' 14.210.115.31 ' (using Password:yes) in C:\xampp\htdocs\projects \ship_thing_swap\mysql\connection.php on line 52

Fatal error:call to undefined function mydsql_error () in C:\xampp\htdocs\projects\ship_thing_swap\mysql\ Connection.php on line 55
Ask the big God this is God horse situation???
------to solve the idea----------------------
$this->conn = mysql_connect ($this->db_host, $this->db_user, $this->db_pwd);
if (! ( $this->conn))
{
Die (' Could not connect: '. Mydsql_error (' connection error '));
}


Spelling errors
------to solve the idea----------------------
observed that
' Noco ' @ ' 14.210.115.31 '
And
' Noco ' @ ' 14.210.115.31 '
The difference
It's obviously a lot more characters like spaces, carriage returns, line feeds, etc.

How did you read the INI file?
------to solve the idea----------------------
That is to remove the trailing white space characters (spaces, carriage returns, line feeds)
$this->db_host = Trim (fgets ($openfile));
$this->db_user = Trim (fgets ($openfile));
$this->db_pwd = Trim (fgets ($openfile));
  • Related Article

    Contact Us

    The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

    If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

    A Free Trial That Lets You Build Big!

    Start building with 50+ products and up to 12 months usage for Elastic Compute Service

    • Sales Support

      1 on 1 presale consultation

    • After-Sales Support

      24/7 Technical Support 6 Free Tickets per Quarter Faster Response

    • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.