Jump to content

Connection error when using require()


Howlin1

Recommended Posts

When I try print some news stories to my homepage I get the following error:

SELECT Error: Can't connect to local MySQL server through socket '/var/lib/mysql/mysql.sock' (2)

 

The code that I am using is:

<?php
require ('news/news.php');
?>

and in the news.php file that code is:

<?php
include 'inc/connect_db.php';

$result = mysql_query("SELECT * FROM site_news") or die("SELECT Error: ".mysql_error());
$num_rows = mysql_num_rows($result);
while ($get_info = mysql_fetch_row($result))
{
echo "<td>{$get_info[1]}</td>";
}
?>

If I go to the news.php file itself, the code will run and I can see the news story that I have.

I have tried using require, require_once, include and include_once but they all come up with the same error.

What am I doing wrong?

Link to comment
https://forums.phpfreaks.com/topic/253492-connection-error-when-using-require/
Share on other sites

Archived

This topic is now archived and is closed to further replies.

×
×
  • 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.