dogfighter Posted October 15, 2008 Share Posted October 15, 2008 I have a script that includes mysqlclass.php which will not connect to my database for some reason. Here is the script up to the line where it dies: <?php include 'mysqlclass.php'; $server = "localhost"; $user = "mydatabase_admin"; $pass = "swordfish"; $database = "mydatabase_name"; $mysql = new MySQL; $mysql->config( $server, $user, $pass, $database ); $mysql->connect() or die("error" . mysql_error()); When I run it, it just prints "error" and does not include any mysql_error. Here is mysqlclass.php: <?php class mysql { function close(){ return @mysql_close($this->conn); } function config( $server, $user, $pass, $database ){ $this->database = $database; $this->pass = $pass; $this->server = $server; $this->user = $user; return true; } function connect(){ $this->conn = mysql_connect($this->server, $this->user, $this->pass) or die ("Unable to connect to Database Server"); @mysql_select_db( $this->database, $this->conn ) or die ("Could not select database"); } function get_results(){ return @mysql_fetch_array( $this->query ); } function get_row(){ return mysql_fetch_row( $this->query ); } function query( $sql ){ return $this->query = mysql_query($sql, $this->conn); } function select_db(){ mysql_select_db( $this->db_name ) or $this->report_error('Error selecting MySQL database. Database name: '.$this->db_name."\r\n"); } } ?> I didn't write the script I'm just trying to fix it... any ideas what's killing it? Link to comment https://forums.phpfreaks.com/topic/128550-solved-script-will-not-connect-to-mysql-why/ Share on other sites More sharing options...
DoddsAntS Posted October 15, 2008 Share Posted October 15, 2008 The connect function in the mysql class doesn't return any value so the line $mysql->connect() or die("error" . mysql_error()); is the reason, the connect function already has error handling in it so why add this when calling the connect function ? if you remove the or die(...blah..) from the above line it should be fine, alternately you could rewite the connect function so it returns a value Link to comment https://forums.phpfreaks.com/topic/128550-solved-script-will-not-connect-to-mysql-why/#findComment-666203 Share on other sites More sharing options...
dennismonsewicz Posted October 15, 2008 Share Posted October 15, 2008 also you declared you class as class mysql and you are calling with new MySQL... I think these are case sensitive. I could be wrong but I think your classes are case sensitive... so if you created it with all lower case then you must call it using lower case. Link to comment https://forums.phpfreaks.com/topic/128550-solved-script-will-not-connect-to-mysql-why/#findComment-666209 Share on other sites More sharing options...
dogfighter Posted October 15, 2008 Author Share Posted October 15, 2008 Great, thank you! Link to comment https://forums.phpfreaks.com/topic/128550-solved-script-will-not-connect-to-mysql-why/#findComment-666215 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.