Page 1 of 1

could not connect to the databaser /

Posted: Tue Dec 14, 2010 5:59 pm
by lin
i try to run a script that makes usage of mysql

all schould run on XAMPP on Linux . but i cannot connect to the database!!

see the following parts ...

db.php

Code: Select all

<?php
$host="localhost"; //database hostname
$username="******"; //database username
$password="******"; //database password
$database="******"; //database name
?>
config.php

Code: Select all

<?php
require_once('db.php'); //call db.php
$connect=mysqli_connect($host,$username,$password); //connect to mysql through mysqli
if(!$connect){
die("Cannot connect to host, please try later."); //throw error if any problem
}
else
{
$select_db=mysqli_select_db($database); //select database
if(!$select_db){
die("Site Database is down at the moment, Please check later. We will be back shortly."); // error if cannot connect to database or db does not exist
}
}
?>
parser.php

Code: Select all

<?php
require_once('config.php'); // call config.php for db connection
$filename = "url.txt"; // Include the txt file which have urls
$each_line = file($filename);
foreach($each_line as $line_num => $line)
{
    $line = trim($line);
    $content = file_get_contents($line);
    //echo ($content)."<br>";
    $pattern = '/<td>(.*?)<\/td>/si';
    preg_match_all($pattern,$content,$matches);

    foreach ($matches[1] as $match) {
        $match = strip_tags($match);
        $match = trim($match);
        //var_dump($match);
        $sql = mysqli_query("insert into tablename(contents) values ('$match')");
        //echo $match;
    } 
}
?>

besides the above mentioned files i have one that is called url.txt
Again - i cannot connect to the db!

Queston: Are there more ways to test the connection to the database!?

look forward to hear from you

regards

Re: could not connect to the databaser /

Posted: Tue Dec 14, 2010 6:02 pm
by Jonah Bron
What error do you get?

Re: could not connect to the databaser /

Posted: Sat Dec 18, 2010 12:05 pm
by lin
hello dear Jonah

many thanks for posting! - Well if i try to find out how to connect to the server - i run a new little test script:

Code: Select all

<?php $link = mysql_connect('localhost','root','');

   if (!$link) { die('Could not connect to MySQL: ' . mysql_error()); }

echo 'Connection OK'; mysql_close($link);

?>
which produces the following results... :

Code: Select all

<?php
PHP Warning:  mysql_connect(): Can't connect to local
MySQL server through socket '/var/run/mysql/mysql.sock'
(2) in /opt/lampp/htdocs/parser_test/db_connector.php on line 7
Could not connect to MySQL:
Can't connect to local MySQL server through
socket '/var/run/mysql/suse-linux:/opt/lampp/htdocs/parser_test #
?>

welll - i have no glue.

BTW - i run XAMPP ver. 1.7.xy on a linux OpenSuse ver. 11.3

Guess that i have messed up the installation!? Is this possible?