affordit Posted February 2, 2008 Share Posted February 2, 2008 I get this error Can't connect to local MySQL server through socket '/tmp/mysql.sock' (46) From this query <?php include("k_falls_dbinfo.inc.php"); mysql_connect(mysql,$username,$password); @mysql_select_db($database) or die(mysql_error()); $query_content= "SELECT * FROM content_table WHERE item = $mynumber"; $result=mysql_query($query_content) or die(mysql_error()); echo $query_content['heading']; echo "<BR>"; echo $query_content['image']; echo "<BR>"; echo $query_content['description']; echo"<BR>"; echo $query_content['description']; ?> Can someone tell me whats wrong? Quote Link to comment https://forums.phpfreaks.com/topic/89090-solved-mysql-error/ Share on other sites More sharing options...
CerealBH Posted February 2, 2008 Share Posted February 2, 2008 im sure ur aware "mysql" dosn't have $ infront of it? are u connecting to another server or is it ont he localhost? Quote Link to comment https://forums.phpfreaks.com/topic/89090-solved-mysql-error/#findComment-456307 Share on other sites More sharing options...
avo Posted February 2, 2008 Share Posted February 2, 2008 Hi Check this line mysql_connect(mysql,$username,$password); Your missing $ should be mysql_connect($mysql,$username,$password); Quote Link to comment https://forums.phpfreaks.com/topic/89090-solved-mysql-error/#findComment-456308 Share on other sites More sharing options...
affordit Posted February 2, 2008 Author Share Posted February 2, 2008 I don't use the $ on any of my queries and the others work OK. I am connecting to the yahoo servers. Quote Link to comment https://forums.phpfreaks.com/topic/89090-solved-mysql-error/#findComment-456310 Share on other sites More sharing options...
p2grace Posted February 2, 2008 Share Posted February 2, 2008 First of all, you need the $ or static text. If the server's on the localhost you could just change it to that with quotes around it. After that try changing the code to this: <?php include("k_falls_dbinfo.inc.php"); mysql_connect('localhost',$username,$password); // this would have to be $mysql if it's not on the localhost @mysql_select_db($database) or die(mysql_error()); $query_content= "SELECT * FROM `content_table` WHERE `item` = '$mynumber'"; $result=mysql_query($query_content) or die(mysql_error()); $arr = mysql_fetch_assoc($result); extract($arr); echo $heading; echo "<br />"; echo $image; echo "<br />"; echo $description; ?> Quote Link to comment https://forums.phpfreaks.com/topic/89090-solved-mysql-error/#findComment-456313 Share on other sites More sharing options...
affordit Posted February 2, 2008 Author Share Posted February 2, 2008 OK tried all of the above and I still get the error Can't connect to local MySQL server through socket '/tmp/mysql.sock' (46) I also dropped the table and rebuilt it and inserted a record to test it still get the same error. I ran queries on the other tables and dbs and they all work fine. Thanks for taking the time to look Any other suggestions?? Quote Link to comment https://forums.phpfreaks.com/topic/89090-solved-mysql-error/#findComment-456338 Share on other sites More sharing options...
Codein Posted February 2, 2008 Share Posted February 2, 2008 I get this error Can't connect to local MySQL server through socket '/tmp/mysql.sock' (46) From this query <?php include("k_falls_dbinfo.inc.php"); mysql_connect(mysql,$username,$password); @mysql_select_db($database) or die(mysql_error()); $query_content= "SELECT * FROM content_table WHERE item = $mynumber"; $result=mysql_query($query_content) or die(mysql_error()); echo $query_content['heading']; echo "<BR>"; echo $query_content['image']; echo "<BR>"; echo $query_content['description']; echo"<BR>"; echo $query_content['description']; ?> Can someone tell me whats wrong? Firstly, you're missing $ from the start of mysql. However, the most prominent error I can see is here: $query_content= "SELECT * FROM content_table WHERE item = $mynumber"; $result=mysql_query($query_content) or die(mysql_error()); echo $query_content['heading']; echo "<BR>"; echo $query_content['image']; echo "<BR>"; echo $query_content['description']; echo"<BR>"; echo $query_content['description']; $query_content doesn't hold any information called from the database. It just holds the mySQL query you wish to execute as a string. $result is what holds the information that has been extracted from the db. However, you can't just extract information from this so you must do: while ($info = mysql_fetch_array($result)) { echo $query_content['heading']; echo "<BR>"; echo $query_content['image']; echo "<BR>"; echo $query_content['description']; echo"<BR>"; echo $query_content['description']; } What this does is loop through the raw information extracted from the database and then puts it into an array, where the keyname for each element is the column header (like, 'heading', 'image', etc). I hope this helps Quote Link to comment https://forums.phpfreaks.com/topic/89090-solved-mysql-error/#findComment-456344 Share on other sites More sharing options...
p2grace Posted February 2, 2008 Share Posted February 2, 2008 Is the database and the php server on the same box? Quote Link to comment https://forums.phpfreaks.com/topic/89090-solved-mysql-error/#findComment-456349 Share on other sites More sharing options...
affordit Posted February 2, 2008 Author Share Posted February 2, 2008 Codein Thanks it did help me understand a little better about how the while loop works. I got it working now I had to drop the db and recreat it then it worked thanks for all your help!! p2grace Yes they are they are both on the Yahoo servers Thanks for your help I now have a better understanding of mysql_fetch_assoc You guys have a great day Thanks Quote Link to comment https://forums.phpfreaks.com/topic/89090-solved-mysql-error/#findComment-456356 Share on other sites More sharing options...
darkfreaks Posted February 2, 2008 Share Posted February 2, 2008 Hit solved topic plz Quote Link to comment https://forums.phpfreaks.com/topic/89090-solved-mysql-error/#findComment-456357 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.