How can I connect to the database using the wp-config.php file ?
I’m trying to make a script more WordPress friendly, and I need to connect to the database, but without installing the script as a plugin.
Basically I have on my script
$host = "xxxxxxxxxxx"; //database location
$user = "xxxxxxxxxxx"; //database username
$pass = "xxxxxxxxxxx"; //database password
$db_name = "xxxxxxxx"; //database name
//Database Connection
$link = mysql_connect($host, $user, $pass);
mysql_select_db($db_name);
The script can not be installed as a plugin (which can make things more easy), so I need to connect to the database using the existing wp-config.php on the installation… Any ideas ???
Thanks in advance
Edit and Clarification
1- I need to use wp-config.php as it is, no modifications.
2- The script will be located at www.example.com/script/
3- It can’t be done as a plugin since the core of the script require to be publicly accessed without any login screen jumping around.
4- My question basically is how to connect to the database using the wp-config.php file by modifying the script above.
2 s
Using the defines the user sets in wp-config:
mysql_connect(DB_HOST, DB_USER, DB_PASSWORD);
EDIT:
Since your script is outside the WordPress environment, what you want to do is initiate it before using the defines in wp-config.
require_once('./path/to/the/wp-config.php');
mysql_connect(DB_HOST, DB_USER, DB_PASSWORD);