riceje7 Posted November 20, 2009 Share Posted November 20, 2009 i'm looking to get a value out of a field named count, in a table named tags, in a database named ricej not sure if this is correct: $sql = "SELECT `count` FROM `tags` WHERE `tagName` = '$word'"; can anyone confirm this or correct it? thanks a bunch Quote Link to comment https://forums.phpfreaks.com/topic/182233-getting-a-value-out-of-a-mysql-table/ Share on other sites More sharing options...
JAY6390 Posted November 20, 2009 Share Posted November 20, 2009 As long as you have a table in your database called tags with the fields tagName and count then yeah Quote Link to comment https://forums.phpfreaks.com/topic/182233-getting-a-value-out-of-a-mysql-table/#findComment-961611 Share on other sites More sharing options...
corbin Posted November 20, 2009 Share Posted November 20, 2009 Why didn't you just try it? Â By the way, count is a reserved word, so don't use it. Â Then, if you rename that column, drop the ` since they're only in MySQL dialect. Quote Link to comment https://forums.phpfreaks.com/topic/182233-getting-a-value-out-of-a-mysql-table/#findComment-961654 Share on other sites More sharing options...
JAY6390 Posted November 20, 2009 Share Posted November 20, 2009 Thats not really great advice to be honest. You should use backticks around all of your table, db and column identifiers to avoid ever getting errors from queries such as the one above without it would produce due to keyword conflict. It's also perfectly acceptable to have a column named count and that is why backticks are there. Â I don't see how using the "sloppy" method is the right way to go on this at all Quote Link to comment https://forums.phpfreaks.com/topic/182233-getting-a-value-out-of-a-mysql-table/#findComment-961837 Share on other sites More sharing options...
cags Posted November 20, 2009 Share Posted November 20, 2009 I always used backticks in the past, but as pointed out by corbin they are not required providing you don't use a reserved word (which is a bad idea anyway), they are also only supported by the MySQL dialect (again as corbin mentioned), making your query less portable. Quote Link to comment https://forums.phpfreaks.com/topic/182233-getting-a-value-out-of-a-mysql-table/#findComment-961854 Share on other sites More sharing options...
JAY6390 Posted November 20, 2009 Share Posted November 20, 2009 Yeah that's a fair point, but how often are they moved to a different SQL server? You're far more likely to use a keyword by accident than you are to change from mysql to another DB kind Quote Link to comment https://forums.phpfreaks.com/topic/182233-getting-a-value-out-of-a-mysql-table/#findComment-961860 Share on other sites More sharing options...
fenway Posted November 24, 2009 Share Posted November 24, 2009 Yeah that's a fair point, but how often are they moved to a different SQL server? You're far more likely to use a keyword by accident than you are to change from mysql to another DB kind It's not a long list to remember. Quote Link to comment https://forums.phpfreaks.com/topic/182233-getting-a-value-out-of-a-mysql-table/#findComment-965112 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.