0

I have got error when try to insert data using PHP code to wordpress database.

Error like this :

Connect failed: Access denied for user 'username'@'localhost' (using password: NO)” in wordpress

How can I fix this.

I'm working on live server.

Syed mohamed aladeen
  • 6,507
  • 4
  • 32
  • 59
Aslam Shekh
  • 1
  • 1
  • 2
  • 2
    you have your database connection credentials setup wrong in `wp-config.php`. – DevDonkey Apr 13 '16 at 13:04
  • I have check wp-config file like this : $wpconfig = dirname( __FILE__ ) . '/wp-config.php'; $contents = file_get_contents( $wpconfig ); foreach ( array( 'DB_NAME', 'DB_USER', 'DB_PASSWORD', 'DB_HOST' ) as $config ) @$link = mysql_connect( $DB_HOST[3], $DB_USER[3], $DB_PASSWORD[3] );if ( ! $link ) { die( sprintf( "Could not connect to the MySQL server: %s\n", mysql_error() ) );}echo "Connected successfully to the MySQL server\n";@$db_selected = mysql_select_db( $DB_NAME[3], $link ); } echo "Database selected successfully\n"; – Aslam Shekh Apr 13 '16 at 13:06
  • Also your earlier post had you connecting to the database as root for your Wordpress operations. This is a bad idea.Create a separate database user and grant rights accordingly. – vogomatix Apr 13 '16 at 13:06
  • my site work fine.but I was create custom table in wordpress database and i have try to insert data using php code. so thats time i got error like above – Aslam Shekh Apr 13 '16 at 13:11
  • Remove ampersands (@) from your code while debugging. They suppress warnings/errors. Also, `$link = mysql_connect( $DB_HOST[3], $DB_USER[3], $DB_PASSWORD[3] );` where are $DB_HOST[3], etc., being set per your comment above? Shouldn't you be using `$config` instead? – mferly Apr 13 '16 at 13:20
  • Yes you are right . established connection successfully.Thanks @Marcus – Aslam Shekh Apr 13 '16 at 13:26

1 Answers1

1

Check your config.php in the main folder and look for this lines if there configure correctly.

/** MySQL database username */
define('DB_USER', '');

/** MySQL database password */
define('DB_PASSWORD', '');

/** MySQL hostname */
define('DB_HOST', 'localhost');
Fil
  • 8,225
  • 14
  • 59
  • 85