I have a problem. I am trying, but I am not getting the exact solution.
I have code to take something from database.
try {
require_once('blogic.php');
$obj = new blogic();
$re = $obj->select("SELECT link FROM eff ORDER BY RAND() LIMIT 1");
$l = mysql_fetch_row($re);
$link = $l[0];
} catch (Exception $e) {
$link = "http://www.xyz.com/friendsin2013/";
}
The above code is working properly, but if (for whatever reason) any problem comes while getting data from the database, I want the link to be defaulted as given in the catch
block.
However it is not working the way I want it to. It works when there is no error, however, when I experience an errorr, $link
does not get passed from the catch
. I just get the error message instead.
Blogic.php life is like --->> This is a file to get database entry.
<?php
include('s.php');
class blogic {
function connect() {
$link = mysql_connect(SERVER, USER, PASSWORD);
if (!$link) {
die('Could not connect: ' . mysql_error());
return false;
} else {
return true;
}
}
function select_database() {
$db = mysql_select_db(DATABASE);
if (!$db) {
die('Could not connect: ' . mysql_error());
return false;
} else {
return true;
}
}
function select($str) {
self::connect();
self::select_database();
$res = mysql_query($str);
return $res;
}
}
?>
s.php ->>