Compressed MySQL Database Connection in 1 Line.

Discussion in 'PHP' started by HungryMinds, Mar 24, 2011.

  1. #1
    I was compressing MySQL Database connection, then finally i compressed it in 1 line.

    Please guide if any error.

    Original MySQL Connection
    
    $localhost = 'localhost';
    $username = '';
    $password = '';
    $database = 'test';
    $link = mysql_connect($localhost, $username, $password);
    if (!$link) {
        die('Not connected : ' . mysql_error());
    }
    $db_selected = mysql_select_db('foo', $link);
    if (!$db_selected) {
        die ('Can\'t use foo : ' . mysql_error());
    }
    
    Code (markup):
    Compressed MySQL Connection
    
    print (!mysql_connect('localhost', '', '')) ? die('DB Connection Error: ' . mysql_error()) : (!mysql_select_db('test')) ? die('DB Selection Error: ' . mysql_error()) : '';
    
    Code (markup):

     
    HungryMinds, Mar 24, 2011 IP
  2. G3n3s!s

    G3n3s!s Active Member

    Messages:
    325
    Likes Received:
    4
    Best Answers:
    0
    Trophy Points:
    80
    #2
    1. I do not see point of this thread
    2. I do not see reason why should you "compress" db connection?
     
    G3n3s!s, Mar 25, 2011 IP