pourmeanother Posted October 27, 2008 Share Posted October 27, 2008 Using the following code I receive "Error" as the output -- meaning I'm not successfully connecting to the MySQL server. PHP4 mysql server version 4.1.14 phpMyAdmin 2.11.9 MySQL client version 3.23.49 (Not sure which of the above is required information) <?php $host="localhost"; $user="user"; $password=" "; $database="databasename"; $cxn = mysql_connect($host, $user, $password); if(!$cxn) { exit("Error"); } $db_selected = mysql_select_db($database); if(!$db_selected) { exit("Could not connect"); } $query = "SELECT * FROM AdamsChristen"; $result = mysql_query($query, $cxn); if(!$result) { exit("Data currently unavailable"); } while( $row = mysql_fetch_assoc($result) ) { extract($row); echo "<table cellspacing='15'>"; echo "<tr><td colspan='5'><hr></td></tr>\n"; echo "<tr> <td>$semester$year</td> <td><b>Helpfulness:</b>\n$helpfulness</td> <td><b>Ease of Grading:</b>\n$grading</td> <td><b>Attention Factor:</b>\n$interesting</td> <td><b>Attendance Mandatory:</b>\n$attendance</td> <td><b>Comments:</b>\n$comments</td> </tr>\n"; echo "<tr><td colspan='5'><hr></td></tr>\n"; } echo "</table>"; mysql_close($cxn); ?> Trying to troubleshoot. All help is appreciated! Link to comment https://forums.phpfreaks.com/topic/130227-error-connecting-to-mysql-server/ Share on other sites More sharing options...
Alt_F4 Posted October 27, 2008 Share Posted October 27, 2008 <?php $host="localhost"; $user="user"; $password=" "; $database="databasename"; ?> are you sure that your password is " " and not ""?? Link to comment https://forums.phpfreaks.com/topic/130227-error-connecting-to-mysql-server/#findComment-675408 Share on other sites More sharing options...
pourmeanother Posted October 27, 2008 Author Share Posted October 27, 2008 Thanks for the prompt reply. Tried changing that, same output. ??? Link to comment https://forums.phpfreaks.com/topic/130227-error-connecting-to-mysql-server/#findComment-675421 Share on other sites More sharing options...
MasterACE14 Posted October 27, 2008 Share Posted October 27, 2008 change this. $cxn = mysql_connect($host, $user, $password); if(!$cxn) { exit("Error"); } to this... $cxn = mysql_connect($host, $user, $password) or die(mysql_error()); see what you get then Link to comment https://forums.phpfreaks.com/topic/130227-error-connecting-to-mysql-server/#findComment-675424 Share on other sites More sharing options...
pourmeanother Posted October 27, 2008 Author Share Posted October 27, 2008 "Can't connect to local MySQL server through socket '/tmp/mysql.sock' (46)" Which I'm assuming has something to do with my setup (or lack of)? Not sure how to resolve that... Link to comment https://forums.phpfreaks.com/topic/130227-error-connecting-to-mysql-server/#findComment-675428 Share on other sites More sharing options...
Fruct0se Posted October 27, 2008 Share Posted October 27, 2008 try editing your settings.php and changing 'localhost' to whatever your hostname is..e.g. 'mysql.mysite.com' Link to comment https://forums.phpfreaks.com/topic/130227-error-connecting-to-mysql-server/#findComment-675431 Share on other sites More sharing options...
pourmeanother Posted October 27, 2008 Author Share Posted October 27, 2008 I did a little more digging, and found that I needed to replace 'localhost' with 'mysql'. Upon doing that, the output was exactly as desired. Thanks for the help, I may be back just yet Link to comment https://forums.phpfreaks.com/topic/130227-error-connecting-to-mysql-server/#findComment-675439 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.