• I have a problem with getting PHP to connect to mysql database
    <?php
    // connect and select a database
    $link = mysql_connect(“vergil.u.washington.edu :18423”, “root”, “new_password”)
    or die (“Couldn’t connect: Check to make sure that:<br>” .

    • your MySQL server is running
    • ” .

    • you used the correct hostname (<tt>vergil/ovid</tt>)
    • ” .
    • you didn’t forget the ‘u’ in the hostname
    • ” .

    • you added a colon with your port number after the hostname
    • ” .

    • you used the username ‘root’
    • ” .

    • you used the correct root password
    • ” .

    • you didn’t forget to close a set of quotation marks
    • <br><br>”);
      print “Connected successfully.<br>”;
      $db = “mysql”;
      mysql_select_db($db) or die(“Could not select the database ‘” . $db . “‘. Are you sure it exists?”);
      // perform an SQL query
      $query = “SELECT * FROM user”;
      $result = mysql_query($query) or die(“Query failed”);
      // print the result of the first row (row counting starts at zero)
      printf(“Host: %s<br>\n”, mysql_result($result, 0, “Host”));
      printf(“User: %s<br>\n”, mysql_result($result, 0, “User”));
      printf(“Grant privilege: %s<br>\n”, mysql_result($result, 0, “Grant_priv”));
      // free result set
      mysql_free_result($result);
      // close the connection
      mysql_close($link);
      ?>
      It won’t let me connect to the Database. do I have to install phpadmin?
      I think the server already supports php since I looked at phpinfo() and there was
      a MSQL heading. But I’m not sure, I’m new to PHP and mysql.

Viewing 4 replies - 1 through 4 (of 4 total)
  • This will check the php
    PHP Info
    Paste this into a new Notepad / BBEdit file
    <?php phpinfo(); ?>
    Save as ‘info.php’
    Upload to server. Visit in your browser (www.example.com/info.php)
    That will give you info about your php version

    MSQL and MYSQL are different. Notice the Y 🙂 Check the phpinfo() again and make sure there is mysql in there, and if not, contact your web host.

    Thread Starter andross

    (@andross)

    Oh what I meant was MySQL. My problem isn’t using phpinfo() but my connect line
    mysql_connect(“vergil.u.washington.edu:18423”, “root”, “new_password”); won’t work.
    I checked and the servername, port, username, and password are all correct. I’m wondering what I could be doing wrong. Does anybody have experience using php and mysql over a University of Washington web server?

    make sure a firewall is not blocking the port you are trying to access 🙂 simple….but sometimes overlooked..

Viewing 4 replies - 1 through 4 (of 4 total)

The topic ‘PHP won’t connect to database’ is closed to new replies.