0

I am trying to create a dynamic page in wordpress that accesses a mysql database. I'm a lot confused about how to go about this. In my wp-config.php file I have the following:

define('DB_NAME', 'sustakp4_WPJ2h');

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

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

/** MySQL hostname */
define('DB_HOST', 'localhost');

I created a php script that looks like:

<?php
   $testConnection  = mysql_connect('localhost', 'sustakp4_WPJ2H', '5bndHPrEZ6df5NNep');
   if (!$testConnection) {
      die('Error: ' . mysql_error());
   }
echo 'Database connection working!';
mysql_close($testConnection);
?>

When I try to run the scipt it says page not working.

how do I connect? When I submit a form what php file is used? What needs to go in it?

Dave
  • 5,108
  • 16
  • 30
  • 40
DCR
  • 14,737
  • 12
  • 52
  • 115
  • What details in the `wp-config` don't match what you said you used to create the database so update `wp-config` so they do. – Dave Sep 25 '19 at 17:17
  • doesn't the database in the wp-config file need to be the default database that's listed? – DCR Sep 25 '19 at 17:29
  • 1
    You might want to change that password now that you've posted it on the internet. – Bill Karwin Sep 25 '19 at 18:12
  • 1
    way ahead of you. changed it before – DCR Sep 25 '19 at 18:22
  • What you have in `wp-config` and what you used for your test does not match what you said you used when you created the database. Use the information, database name, user and password that you used when you created the database. – Dave Sep 25 '19 at 18:22
  • no, you're wrong. The information in the wp_config file doesn't matter. The problem is I need to use new sqli(); – DCR Sep 25 '19 at 18:23

1 Answers1

1

You are not adding database username Try this :

<?php $mysqli = new mysqli("localhost", "username", "password", "dbname"); ?>

if this does not help try this article https://api-integration.org/php-code-to-connect-with-mysql-database/. it might help