2
$link = mysql_connect($db_host, $db_user, $db_password);
if (!$link) {
  die ("MySQL Connection error");
}


mysql_select_db($db_name, $link) or die ("Wrong MySQL Database");

i tried to code some lines if $link or $db_name not ok echo some text

something like this

if (!$link || !$db_name) {
  echo 'Some Text Here';
}

but it didn't work

please how i can do that ?

user2005646
  • 148
  • 3
  • 16
  • Please, don't use mysql_* functions for new code. They are no longer maintained and are [deprecated as of PHP 5.5.0](http://php.net/manual/en/intro.mysql.php). See the [red box](http://goo.gl/GPmFd)? Instead learn about [prepared statements](http://goo.gl/vn8zQ) and use either [PDO](http://php.net/pdo) or [MySQLi](http://php.net/mysqli). If you can't decide, [this article](http://goo.gl/3gqF9) will help you to choose. If you care to learn, here is good [PDO tutorial](http://goo.gl/vFWnC). – peterm Jan 26 '13 at 04:54

1 Answers1

2

mysql_select_db is a boolean function, so.

$link = mysql_connect($db_host, $db_user, $db_password);

$db = mysql_select_db($db_name, $link);

if(!$link && !$db) {
  echo "nothing works";
}

But please, don't use mysql_* functions in new code. They are no longer maintained and are officially deprecated. See the red box? Learn about prepared statements instead, and use PDO, or MySQLi - this article will help you decide which.

Zoe
  • 27,060
  • 21
  • 118
  • 148
Kermit
  • 33,827
  • 13
  • 85
  • 121