Allowed characters for mysql_connect parameters

Discussion in 'PHP' started by ignas2526, Oct 6, 2009.

  1. #1
    Hello,
    I'm trying to find what characters are allowed to use for server, username, password, and database name(this one is actually from mysql_select_db).
    I tried to create table with name like !#()_{}'"s@$ and it worked, so I'm totally confused about which characters are allowed and which not allowed.
    Thanks for advice.
     
    ignas2526, Oct 6, 2009 IP
  2. premiumscripts

    premiumscripts Peon

    Messages:
    1,062
    Likes Received:
    48
    Best Answers:
    0
    Trophy Points:
    0
    #2
    For table names there isn't much that isn't allowed. See http://dev.mysql.com/doc/refman/5.1/en/identifiers.html

    And a length of 64 chars max. Ofcourse, this is for mysql 5.1. Other restrictions may apply to earlier versions.

    If you use special characters, like for example + and -, you should use the ` operator so as not to confuse mysql.

    So you should construct your SQL like so: SELECT * from `jksd@sdj+`

    Of course, I see no good reason why you'd want to use names such as this..
     
    premiumscripts, Oct 6, 2009 IP
  3. ignas2526

    ignas2526 Peon

    Messages:
    75
    Likes Received:
    0
    Best Answers:
    0
    Trophy Points:
    0
    #3
    @premiumscripts: thanks for quick reply, well actually I don't want to use such characters, I need this for creating validation.
     
    ignas2526, Oct 6, 2009 IP
  4. premiumscripts

    premiumscripts Peon

    Messages:
    1,062
    Likes Received:
    48
    Best Answers:
    0
    Trophy Points:
    0
    #4
    Well, ok, in that case i would just allow a-z and _. Seems like most people wouldn't need anything else.
     
    premiumscripts, Oct 6, 2009 IP