could not connect to the databaser /
Posted: Tue Dec 14, 2010 5:59 pm
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
config.php
parser.php
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
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
?>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
}
}
?>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