Jump to content

Recommended Posts

Hello, I own Nebraska Geek, and I am also the webmaster. We have tried to implement our news into a MySQL database.

Database table (news) consists of postTitle,postBody,author,date,type (all VARCHARS) and postNumber (INT).

 

below is the i used to get it:

 

$dbhost = "nebraskageek.fatcowmysql.com";
$dbname = "beta";
$dbuser = "gulliccj";
$dbpass = "pepper8";
mysql_connect ( $dbhost, $dbuser, $dbpass)or die("Could not connect: ".mysql_error());
mysql_select_db($dbname) or die(mysql_error());
$query  = "SELECT * FROM news";
$result = mysql_query($query);
$ii = mysql_num_rows($result)-1;
for($i = 0; $i<=$ii;$i++)
{	
//2nd time through returns: Can't connect to local MySQL server through socket '/var/run/mysqld/mysqld.sock' (2)
$query2 = "select * from news where postNumber='$i'";  
$result2=mysql_query($query2)or die(mysql_error());
$row = mysql_fetch_array( $result2 );
mysql_close();
$pt=$row['postTitle'];
$pb=$row['postBody'];
$a=$row['author'];
$d=$row['date'];
$t=$row['type'];
$n =$row['postNumber'];
    echo  "<hr><div id='title'>$pt</div> <br>".
         "<div id='post'>$pb <hr>".
         "$a $d <br>Category: $t </div><hr>";
} 
mysql_close();

 

but it returns:Can't connect to local MySQL server through socket '/var/run/mysqld/mysqld.sock' (2)Can't connect to local MySQL server through socket '/var/run/mysqld/mysqld.sock' (2) its second time through the loop, and displays a blank post...why? thanks so much for reading.

Link to comment
https://forums.phpfreaks.com/topic/181610-help-with-phpmysql/
Share on other sites

The error message means that the $dbhost name you are using is not that of an actual mysql server.

 

On shared web hosting it will be something like mysqlx.yourwebhost.com You would need to check with your web host to be sure what it is on your server. Your database management tool (where you created the database, username, and password) typically displays the correct mysql server host name to use in the connection.

Link to comment
https://forums.phpfreaks.com/topic/181610-help-with-phpmysql/#findComment-957993
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.