FRIHOST FORUMS SEARCH FAQ TOS BLOGS COMPETITIONS
You are invited to Log in or Register a free Frihost Account!


Trying to Understand MySQL Syntax





Possum
Hi

I am learning MySQL and although I understand what

Code:
mysql_connect([host][, user_name][, password]);


Means.

I would have written it like this

Code:
mysql_connect([host],[ user_name],[ password]);


Why are the comma in the position they are in.

Thank you..
Peterssidan
What's inside the [] is optional. If it was
Code:
mysql_connect([host],[ user_name],[ password]);

you still have to place the commas but don't have to place something inside. Which means you could leave out the first parameter but specify the second etc. You don't want this.
Code:
mysql_connect($host,,);
mysql_connect(,,$password);



You write it is
Code:
mysql_connect([host][, user_name][, password]);

but I think it should be like this
Code:
mysql_connect([host[, user_name[, password]]]);

(The real function has more optional arguments). This means you don't have to give any argument, or you can give host, optianally followed by a comma and the user name, optionally followed by a comma and the password. Get it?

And this is not MySQL syntax. It is PHP.
Nemesis234
Code:
mysql_connect("localhost","user","pass")  or die("Could not connect: " . mysql_error());
mysql_select_db("dbname");


i personally connect like so, works for me, and makes much more sense then what you have Razz
kacsababa
Quote:
And this is not MySQL syntax. It is PHP.
Even more it closer to php manual syntax not php itself.
welshsteve
Nemesis234 wrote:
Code:
mysql_connect("localhost","user","pass")  or die("Could not connect: " . mysql_error());
mysql_select_db("dbname");


i personally connect like so, works for me, and makes much more sense then what you have Razz


This is how I connect as well. Works perfectly well for me.
Related topics
a site where i can learn mysql syntax
mysql syntax error I can't find why
mysql syntax problem
Creating a Search Script with PHP for MySQL
Error 127 from PHPbb
Firefox userChrome.css/icons question
[PHP] Parse error
What order do you suggest in learning web programming?
Seach MySQl for muiltipe variables
Cannot insert data with single quote (Solved by Sonam)
PHP DB Error: syntax error
Updating multiple MySQL rows at once
ALTER TABLE mySQL problem.
Need help understanding MySQL "Resource" type retu
Reply to topic    Frihost Forum Index -> Scripting -> Php and MySQL

FRIHOST HOME | FAQ | TOS | ABOUT US | CONTACT US | SITE MAP
© 2005-2011 Frihost, forums powered by phpBB.