cheechm Posted October 3, 2007 Share Posted October 3, 2007 Hi, I can't seem to be able to connect to a database. functions.php require_once 'config.php'; class DBConnect extends SystemComponent { var $theQuery; var $link; //*** Function: DbConnect, Purpose: Connect to the database *** function DBconnect(){ // Load settings from parent class $settings = SystemComponent::getSettings(); // Get the main settings from the array we just loaded $host = $settings['dbhost']; $db = $settings['dbname']; $user = $settings['dbusername']; $pass = $settings['dbpassword']; // Connect to the database $this->con = mysql_connect("$host", "$user", "$pass") or die(mysql_error()); mysql_select_db("$db", $this->con); register_shutdown_function(array(&$this, 'close')); } //*** Function: query, Purpose: Execute a database query *** function query($query) { $this->theQuery = $query; return mysql_query($query, $this->con); } //*** Function: fetchArray, Purpose: Get array of query results *** function fetchArray($result) { return mysql_fetch_array($result); //*** Function: close, Purpose: Close the connection *** function close() { mysql_close($this->con); } } } config.php class SystemComponent { var $settings; function getSettings() { // System variables $settings['siteDir'] = '****'; // Database variables $settings['dbhost'] = '****; $settings['dbusername'] = '***'; $settings['dbpassword'] = '***'; $settings['dbname'] = '***'; return $settings; } } I get this error when trying to connect to the database: Warning: mysql_connect() [function.mysql-connect]: Can't connect to MySQL server on 'sql12.streamline.net' (4) in functions.php on line 26 Can't connect to MySQL server on 'sql12.streamline.net' (4) What is the problem? Many thanks. Quote Link to comment https://forums.phpfreaks.com/topic/71733-solved-connecting-to-the-database/ Share on other sites More sharing options...
willpower Posted October 3, 2007 Share Posted October 3, 2007 you have actually set the user name and password etc haven't you and arent just using a generic script? Quote Link to comment https://forums.phpfreaks.com/topic/71733-solved-connecting-to-the-database/#findComment-361272 Share on other sites More sharing options...
cheechm Posted October 4, 2007 Author Share Posted October 4, 2007 I am definetley putting passwords (right one at that) Quote Link to comment https://forums.phpfreaks.com/topic/71733-solved-connecting-to-the-database/#findComment-361760 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.