Now I was working with the database and I was puzzled by the question:
$db_res = sqlite_open( $db_name ) || die (" !" ); $query = sqlite_query($db_res, "SELECT * FROM $table") || die (' !');
I get an error when using “|| die()”
Warning: sqlite_query() expects parameter 1 to be resource, string given in ... on line ...
If you change the operator “||” on “or” everything works correctly, why?
Answer 1, authority 100%
This is because the
||operator has a higher precedencethan the
$db_reswill be set to the result of
sqlite_open( $db_name ) || die (" !" ), i.e. true.
oroperator, on the contrary, has prioritythan
$db_reswill first be assigned the result of
sqlite_open( $db_name )and only then will the logical OR be applied:
$db_res || die (" !" )
I.e. if you explicitly prioritize, then both expressions will look like this:
$db_res = ( sqlite_open( $db_name ) || die (" !" ) ); ( $db_res = sqlite_open( $db_name ) ) or die (" !" );
And programming conventions say that OR and AND must be used before || and &&. So I advise you to use the alphabetic version.