Liquid Fire Posted March 11, 2008 Share Posted March 11, 2008 I have been tought that using the tilde key aroun f data, table, and fields is proper, is the any reason for it? The only thing i can think of it so i can use mysql key word as field/table/database name if needed, just wondering if there is any other reason. Quote Link to comment Share on other sites More sharing options...
fenway Posted March 11, 2008 Share Posted March 11, 2008 Nope, that's the only reason... but it's better to simply avoid using any such keywords -- and the only way to know you've stumbled upon one if you leave the backticks out. Quote Link to comment Share on other sites More sharing options...
Liquid Fire Posted March 11, 2008 Author Share Posted March 11, 2008 wouldn't it be better to include the tilde keys? Quote Link to comment Share on other sites More sharing options...
fenway Posted March 11, 2008 Share Posted March 11, 2008 wouldn't it be better to include the tilde keys? Not really -- why go looking for problems? Name your columns with underscores so that you won't ever run into this issue, and you're done. No backticks that mask potential problems. Quote Link to comment Share on other sites More sharing options...
Liquid Fire Posted March 11, 2008 Author Share Posted March 11, 2008 Well i guess i trying to say it seems like it would be safer to also use the tilde key as it won't create a problem as far as i can see. I am building a framework and if another person want to name there table or field a certain why, i don't feel i should stop them. I mean what harm does having the tilde key give beside not allowing you to use mysql keywords(which to me is a good thing, it will make sure the query never breaks in case you have to inherit a database structure or something)? Quote Link to comment Share on other sites More sharing options...
fenway Posted March 11, 2008 Share Posted March 11, 2008 Well i guess i trying to say it seems like it would be safer to also use the tilde key as it won't create a problem as far as i can see. I am building a framework and if another person want to name there table or field a certain why, i don't feel i should stop them. I mean what harm does having the tilde key give beside not allowing you to use mysql keywords(which to me is a good thing, it will make sure the query never breaks in case you have to inherit a database structure or something)? Because it's a band-aid solution -- I wouldn't allow anyone to use reserved keywords in MY framework. But if you're not suck a stickler, go right ahead. I'm just tired of having columns named "date", "time", "desc", etc. Quote Link to comment Share on other sites More sharing options...
Liquid Fire Posted March 12, 2008 Author Share Posted March 12, 2008 I guess anyone using my framework(and i really don't except it to be that many) are not going to be using old database structures. I am rebuilding my mysql class to use pdo an di guess i will take the tildes out, it won't effect me and that is the main person this framework it for. Quote Link to comment Share on other sites More sharing options...
PFMaBiSmAd Posted March 12, 2008 Share Posted March 12, 2008 FYI - a tilde is the wavy line ~. The ` is called a back-tick. The back-tick around an identifier is not standard sql. It is mysql specific. Double-quotes around an identifier are used in standard sql (and mysql allows it if so configured.) If you expect your application to be used on a different database or if mysql chooses to more closely follow standards in the future, using the back-tick should be avoided. Quote Link to comment Share on other sites More sharing options...
Liquid Fire Posted March 12, 2008 Author Share Posted March 12, 2008 Do other databases require double quote around identifier? Quote Link to comment Share on other sites More sharing options...
fenway Posted March 12, 2008 Share Posted March 12, 2008 Do other databases require double quote around identifier? Every DB has a way to "escape" keywords. Quote Link to comment Share on other sites More sharing options...
trq Posted March 12, 2008 Share Posted March 12, 2008 Do other databases require double quote around identifier? No databases that I'm aware of do. Strings need to be surrounded with quotes (sinlge or double). but yeah, as has been said (and especially if your aiming to make your framework db indepedent) the use of backticks should be avoided. Its not standard sql, and is not supported by most DBMS's. Quote Link to comment Share on other sites More sharing options...
Liquid Fire Posted March 12, 2008 Author Share Posted March 12, 2008 yea, i want it to be easily db independent(that why i am switch to PDO) so i think the best case to not to allow escaping of keywords if no database required it. As long it it is just a way to escape keywords and not a requirement, i will just not allow it for best practices purpose. Quote Link to comment Share on other sites More sharing options...
Liquid Fire Posted March 12, 2008 Author Share Posted March 12, 2008 another question about the backtick character is that can is be included in a double or single quoted string as part of the string? Quote Link to comment Share on other sites More sharing options...
fenway Posted March 12, 2008 Share Posted March 12, 2008 another question about the backtick character is that can is be included in a double or single quoted string as part of the string? Yes.. otherwise you could never use it in PHP! Quote Link to comment Share on other sites More sharing options...
Liquid Fire Posted March 12, 2008 Author Share Posted March 12, 2008 I meant in a MySQL string. So would "asdfasdfasdf`sdfgsdfgsdfg" and/or 'adsfasdfasdfasdf`adfasdf' be valid or would they fail if i tried them in a query? Quote Link to comment Share on other sites More sharing options...
Barand Posted March 12, 2008 Share Posted March 12, 2008 As well as reserved words, the back-ticks also let you have column or table names that contain spaces. These, like reserved words, should be avoided too. The only time, IMO, that you would need them is when writing an application where you need to use column/table names from variables and the names are up to the user and largely outside you control. eg CREATE TABLE `$tablename` ( blah .... ) where $tablename was input by the user. And yes, you could "SELECT foo FROM bar WHERE fubar = 'abc`def`gh' " Quote Link to comment Share on other sites More sharing options...
fenway Posted March 13, 2008 Share Posted March 13, 2008 Depends... as "strings" or as identifiers? Quote Link to comment Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.