|
This script tests a database connection to a MySQL Database using the built-in Joomla mysql driver.
- Save this script as mysql.php in your root folder of your Joomla installation.
- Configure the database username, password etc in the script
- Open a web browser and load the script, e.g. http://yoursite/mysql.php
If you get a green OK echoed back then the connection was successful. If not, please study the error messages and try to figure out what is the problem.
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
|
<?php
///////////////////////////////////////////////////
// Joomla-R-Us
//
// Connection test to external MySQL database
//
///////////////////////////////////////////////////
// Configurations below!!
///////// Bootstrap the Joomla Framework //////////////
define( '_JEXEC', 1 );
define('JPATH_BASE', dirname(__FILE__) );
define( 'DS', DIRECTORY_SEPARATOR );
require_once ( JPATH_BASE .DS.'includes'.DS.'defines.php' );
require_once ( JPATH_BASE .DS.'includes'.DS.'framework.php' );
/**
* CREATE THE APPLICATION
*
* NOTE :
*/
$mainframe =& JFactory::getApplication('site');
/**
* INITIALISE THE APPLICATION
*
* NOTE :
*/
// set the language
$mainframe->initialise();
JPluginHelper::importPlugin('system');
// trigger the onAfterInitialise events
$mainframe->triggerEvent('onAfterInitialise');
/////////////////////////////////////////////////////
///////////// Configure this ////////////////////////
$hostname = 'myhost.mydomain.com';
$username = 'myaccount';
$password = 'mypassword';
$database = 'joomla';
///////////// End Configure ////////////////////////
// Try connecting to the database
$option = array ();
$option ['driver'] = 'mysql';
$option ['host'] = $hostname;
$option ['user'] = $username;
$option ['password'] = $password;
$option ['database'] = $database;
$option ['prefix'] = '';
$db = JFactory::getDBO ();
$db = & JDatabase::getInstance ($option);
if ( get_class($db) == 'JDatabaseMySQL' ) {
echo '<b><font color="green">OK!</font></b>';
} else {
echo '<b><font color="red">FAILED</font></b> : ' . $db->message;
}
?>
|
 |