Double Die(),FIRST DIE WORKED

Hello.why my second die() not worked ?

<?php
mysql_connect("localhost","id2134350_egor","26718323aA")
or die ("<p>Error sql connection: " . mysql_error() . "</p>");

echo "<p>Connection ok</p>";

mysql_select_db("id2134350_greendale")
or die ("<p>Error database selected: " . mysql_error() . "</p>");

echo "<p>Database selected</p>";
?>

@Greendalee First i would suggest use “mysqli” function, as “mysql” function is deprecated.
Then try again.

<?php $mysqli = mysqli_connect("localhost", "id2134350_egor", "26718323aA"); /* проверяем соединение */ if (mysqli_connect_errno()) { echo " fuck off"; } $selecting = mysqli_select_db($mysqli,"id2134350_greendale"); if (!mysqli_select_db($mysqli,"id2134350_greendale")) { echo "suck"; }

Hi @Greendalee!

Your code is not managed correctly. You’ll have to assign the connections to certain variables. Also, as @akhilkumar332 suggested, it’s better to use mysqli_* instead.

Use this sample code:

$host = 'xxx';
$username = 'xxx';
$password = 'xxx';
$database = 'xxx';

$connection = mysqli_connect($host, $username, $password, $database); // connect and select the database at the same time;

if(!$connection)  // prints connection error if any
{
  die(mysqli_connect_error());
}

$query = mysqli_query($connection, "SELECT * FROM xxx"); // the query to execute; result will be assigned as object to $query

if(!$query)  // prints query error if any
{
   die(mysqli_error($connection));
}

mysqli_close($connection);  // disconnects $connection from MySQL server

why my second die() not worked ?

die() kills the execution of the script. If you have passed one die() it’s natural that the next ones will not be passed as the execution of the script will be stopped.