Reply to Re: [PHP] Re: syntax error, unexpected T_STRING

Your name:

Reply:


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]


Удаленная работа для программистов  •  Как заработать на Google AdSense  •  England, UK  •  статьи на английском  •  PHP MySQL CMS Apache Oscommerce  •  Online Business Knowledge Base  •  DVD MP3 AVI MP4 players codecs conversion help
Home  •  Search  •  Site Map  •  Set as Homepage  •  Add to Favourites

Copyright © 2005-2006 Powered by Custom PHP Programming

Сайт изготовлен в Студии Валентина Петручека
изготовление и поддержка веб-сайтов, разработка программного обеспечения, поисковая оптимизация