| 
	
 | 
 Posted by Jochem Maas on 07/18/05 23:34 
George B wrote: 
> George B wrote: 
>  
>> I am trying to connect to a datbase: 
>> 
>> " 
>> mysql_select_db ('database') 
>>     or die ("couldnt connect to databse") 
>> " 
>> What is wrong here? 
>> This is the error: 
>> 
>> Parse error: syntax error, unexpected T_STRING in file name on line 12 
>  
> this code works though 
 
the semicolon delimits a single statement (however complex). 
tabs and spaces have no 'token' meaning. as in the parser doesn't give a 
hoot if you write the whole scripton a single line. (I use the word statement 
but I'm not sure that's the correct name for it - anyone care to add?) 
if/else/else if/while/for(/etc?) have the quality that you can leave 
out the braces if you are only wish to conditionally execute 1 statement 
.... e.g: 
 
// run this on the cmdline or change the '\n's to '<br />' 
$a = $b = $c = "A"; $d = array("A"); $e = "B"; 
 
echo "\nplainfoos and foofoos:\n"; 
 
// this one you dont see (the silentfoo) 
if (!in_array(str_replace($a,$b,$c),$d)) 
	echo "silentfoo\n"; 
 
// this is like the next one 
if (in_array(str_replace($a,$b,$c),$d)) 
	echo "foo\n"; 
 
// this is like the previous one 
if (in_array(str_replace($a,$b,$c),$d)) { 
	echo "foo\n"; 
} 
 
/////////////////////////////////// 
 
// this is not like the next one 
if (in_array(str_replace($a,$b,$c),array($e))) 
	echo "foo"; 
	echo "foo\n"; 
 
// this is not like the previous one 
if (in_array(str_replace($a,$b,$c),$d)) { 
	echo "foo"; 
	echo "foo\n"; 
} 
 
and now a word from our sponsor for this evening about die()ing ... 
>  
> $db = mysql_connect("localhost", "myaccount", "mypass") or die("Could  
> not connect."); 
 
<? 
function yourmoney($kids = 1) { return 80 - (90 * $kids); } 
function yourlife($lastWords = "errr") { die(strval($s)); } 
 
yourmoney() or yourlife("is no choice at all."); 
?> 
 
(it has to be added that we are talking about those special kind of 
children that are capable of 'breaking' your friends Hummer ;-)) 
 
[not a true story - just popped into my head.] 
 
> if(!$db) 
>     die("no db"); 
> if(!mysql_select_db("database",$db)) 
>      die("No database selected."); 
 
die(); die(); die() ... see it doesn't even sound very nice ;-) 
 
have fun! 
 
>
 
[Back to original message] 
 |