Women in Technology

Hear us Roar



Article:
  Using MySQL from PHP
Subject:   Connect to MySQL DB
Date:   2006-05-09 17:00:30
From:   Cleo
I have a hosting account with GODADDY.com where I've been assigned a MySQL database. But I'm having trouble connecting to it. My code is as follows:


//Connect To Database
$hostname="mysql.secureserver.net";
$username="cdphillips";
$password="*******";
$dbname="cdphillips";
$usertable="Contacts";
$yourfield = "F_Name";
$conn=mysql_connect($hostname,$username, $password) or die ('Error connecting to mysql');
mysql_select_db($dbname);


# Check If Record Exists


$query = "SELECT * FROM $usertable";


$result = mysql_query($query);


if($result)
{
while($row = mysql_fetch_array($result))
{
$name = $row["$yourfield"];
echo "Name: ".$name."
";
}
}


What's wrong please?

Full Threads Oldest First

Showing messages 1 through 7 of 7.

  • Connect to MySQL DB
    2007-12-15 08:23:06  krsbuilt [View]

    Your Problem is that the database connection isn't using the mysql connection. If you did it like this:

    mysql_connect($hostname,$username, $password) or die ('Error connecting to mysql');
    mysql_select_db($dbname);

    it might work. since you were making the mysql cnnection a variable, your database connection couldn't use it. now if you make the mysql connection not a variable then anything in the script can access it.
    • Connect to MySQL DB
      2009-06-22 20:04:54  mfoster978 [View]

      I need help. I have been working on my site for days now and am having a problem. I am receiving an error saying the script could not connect to my sql. My script seems perfectly fine but it won't connect. Also I am using godaddy and a windows hosting account. Is there a chance it won't connect unless I change to linux?

      My script is below:


      <?
      /**
      * Connect to the mysql database.
      */
      $conn = mysql_connect("p3nlmysqladm001.secureserver.net:", "loginform978", "************") or die(mysql_error());
      mysql_select_db('loginform978', $conn) or die(mysql_error());

      ?>


      I have also tried this:
      <?
      /**
      * Connect to the mysql database.
      */
      $conn = mysql_connect("p3nlmysqladm001.secureserver.net:3306", "loginform978", "************") or die(mysql_error());
      mysql_select_db('loginform978', $conn) or die(mysql_error());

      ?>

      Please help me. If you need to please contact me at mike_foster@tmail.com.

      Thanks,
      Mike Foster
      • Connect to MySQL DB
        2009-07-05 20:17:09  Reloaded2010 [View]

        Remove the colon : after the server name. Use just p3nlmysqladm001.secureserver.net and you should be ok.
  • Connect to MySQL DB
    2007-11-04 03:21:29  dashtimothy2000 [View]

    hi good day to you. i got similar problem. Im new to php and i cannot connect to my databse either heres my connection code:

    $link = mysql_connect("localhost","my_db","my_passwrd")
    or die("Could not connect : " . mysql_error());

    Wander if you have got the reply on your prob and if you can help me with ths.

    Thank you

    Dennis
  • Connect to MySQL DB
    2006-05-31 23:12:22  PrabhjotSingh [View]

    HI

    I am facing a similar but a litle diffrent problem. My hosting too is at godaddy.com and my sql server is too here but now i want to connect to this mysql from my another web server which is not on godaddy.com. I think its netsol or somewhat. If you get solution for urs could you solve mine pls.

    Thanks
    • Connect to MySQL DB
      2006-06-03 05:16:23  sandeep_raju [View]

      HI


      I am facing a similar but a litle diffrent problem. i just want to know the all code of connecting and
      retrieving data from mysql using php.



      Thanks
    • Connect to MySQL DB
      2006-06-02 13:08:43  Aethenoth [View]

      According to their FAQ, you cannot connect to the godaddy mysql servers from outside of godaddy. Access is limited to code you run on their hosting packages.