• Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 500
  • Last Modified:

MySql Connection

I currently have a MySql database that is hosted in a CPanel shared enviroment. Here is the current configuration:

$hostname_username_dbname = "localhost";
$database_username_dbname = "username_dbname";
$username_username_dbname = "username_user";
$password_username_dbname = "password";
$username_dbname = mysql_pconnect($hostname_username_dbname, $username_username_dbname, $password_username_dbname) or trigger_error(mysql_error(),E_USER_ERROR); 
?>

Open in new window


username = cpanel username and dbname= the database name.

I want to move this connection to a godaddy hosting account but the database is diffrent. I dont have the username_dbname format. From GD I have

Host: connect.godaddy.com
User: Username
Database: Username
Password: Password

I am new at MySql and would like to see if someone can give me a hand with the connection string listed above.
0
CCSNV
Asked:
CCSNV
  • 4
  • 4
  • 4
  • +3
3 Solutions
 
Guy Hengel [angelIII / a3]Billing EngineerCommented:
your code seems ok ... what is the issue you get?

if the only issue is the database/usernames in the code, well, that should be fixed easily, no?
0
 
andreizzCommented:
username_dbname is just a name, it doesn't follow any format, whatever you say in the " " is the database name so if on GoDaddy the db name is just your username, put that.
0
 
CCSNVAuthor Commented:
Correct just plug in the information for the host, username, password, and database name. I was thrown this project and know very little about MySql connection strings. Do i need to edit anything from line 5 and 6 above or 1-2 here:

$username_dbname = mysql_pconnect($hostname_username_dbname, $username_username_dbname, $password_username_dbname) or trigger_error(mysql_error(),E_USER_ERROR); 
?> 

Open in new window

0
Cloud Class® Course: Python 3 Fundamentals

This course will teach participants about installing and configuring Python, syntax, importing, statements, types, strings, booleans, files, lists, tuples, comprehensions, functions, and classes.

 
Dave BaldwinFixer of ProblemsCommented:
Just put the new values in the appropriate variables.  That's all I had to do on the installations I have on Godaddy, both Windows and Linux hosting.
0
 
Julian MatzJoint ChairpersonCommented:
Hi!

All you need to change is this:

$hostname_username_dbname = "connect.godaddy.com";
$database_username_dbname = "ENTER DATABASE NAME HERE";
$username_username_dbname = "ENTER YOUR GODADDY USERNAME HERE";
$password_username_dbname = "ENTER YOUR GODADDY PASSWORD HERE";

Open in new window


That's it, you don't have to make any other changes.
0
 
Ray PaseurCommented:
You're moving TO GoDaddy?  Before you do that, call their tech support and see how quickly and how well they answer this question!

I don't think you get any advantage from using pconnect().  This code shown below should work (or something very close to it).
<?php // RAY_mysql_example.php
error_reporting(E_ALL);


// IMPORTANT PAGES FROM THE MANUALS
// MAN PAGE: http://php.net/manual/en/ref.mysql.php
// MAN PAGE: http://php.net/manual/en/mysql.installation.php
// MAN PAGE: http://php.net/manual/en/function.mysql-error.php


// CONNECTION AND SELECTION VARIABLES FOR THE DATABASE
$db_host = "localhost"; // PROBABLY THIS IS OK
$db_name = "??";        // GET THESE FROM YOUR HOSTING COMPANY
$db_user = "??";
$db_word = "??";

// OPEN A CONNECTION TO THE DATA BASE SERVER
// MAN PAGE: http://php.net/manual/en/function.mysql-connect.php
if (!$db_connection = mysql_connect("$db_host", "$db_user", "$db_word"))
{
    $errmsg = mysql_errno() . ' ' . mysql_error();
    echo "<br/>NO DB CONNECTION: ";
    echo "<br/> $errmsg <br/>";
}

// SELECT THE MYSQL DATA BASE
// MAN PAGE: http://php.net/manual/en/function.mysql-select-db.php
if (!$db_sel = mysql_select_db($db_name, $db_connection))
{
    $errmsg = mysql_errno() . ' ' . mysql_error();
    echo "<br/>NO DB SELECTION: ";
    echo "<br/> $errmsg <br/>";
    die('NO DATA BASE');
}
// IF WE GOT THIS FAR WE CAN DO QUERIES

Open in new window

0
 
Ray PaseurCommented:
And on line 12, you might want to have this:

$db_host = "connect.godaddy.com";
0
 
Julian MatzJoint ChairpersonCommented:
Or even better: MySQLi (MySQL Improved Extension) :)
http://php.net/manual/en/book.mysqli.php
<?php

$db_host = "connect.godaddy.com";
$db_user = "USERNAME";
$db_pass = "PASSWORD";
$db_name = "DATABASE";

$mysqli = new mysqli( $db_host, $db_user, $db_pass, $db_name );

/*
 * This is the "official" OO way to do it,
 * BUT $connect_error was broken until PHP 5.2.9 and 5.3.0.
 */
if ($mysqli->connect_error) {
    die('Connect Error (' . $mysqli->connect_errno . ') '
            . $mysqli->connect_error);
}

/*
 * Use this instead of $connect_error if you need to ensure
 * compatibility with PHP versions prior to 5.2.9 and 5.3.0.
 */
if (mysqli_connect_error()) {
    die('Connect Error (' . mysqli_connect_errno() . ') '
            . mysqli_connect_error());
}

echo 'Success... ' . $mysqli->host_info . "\n";

$mysqli->close();
?>

Open in new window

0
 
Dave BaldwinFixer of ProblemsCommented:
There's nothing weird or different about Godaddy for PHP/MySQL connections like this.  Just like any other hosting, you get the connection info when you set up the database and you plug it in.  I've taken the code I use on my Linux and Windows servers here and used it on Godaddy just by changing the connection and login details.

And I've had more trouble with customer service on 1and1 and Network Solutions than I have with Godaddy.  No, they don't know everything but they've been cooperative and helpful.  Can't say that of all the hosting companies I've had to deal with.
0
 
Julian MatzJoint ChairpersonCommented:
I think what Ray meant to say was that opening a persistent MySQL connection might not be the best option, depending on.
0
 
Ray PaseurCommented:
@DaveBaldwin:  I do not have anything against GoDaddy, but my experience with their technical support would have been laughable if it had not come at the cost of hours of my life trying to explain to GoDaddy that "MySQL Server Has Gone Away" was not an application programming problem.  I found them to be incompetent, and even if they were trying to be helpful their unfocused efforts resulted in a huge waste of my time.  Had this happened once I would write it off, but I have four such experiences with hosting-related failures at GoDaddy.  And in my experience the most important thing to them was to get me off the phone as fast as they could.  I have had similar "support" experiences with SiteGround - a simply terrible company for their customers.  I have heard stories about 1and1, but I've never been caught up with them.  

In contrast, almost every other host I have used has sharp telephone and email support, and a real commitment to client satisfaction.  My favorites include ChiHost, Liquid Web, DreamHost, Pair, and HostGator.  For roll-your-own, Rackspace seems to be in the center of gravity.

That's just my $0.02.  Danica Patrick is cute, but my clients don't give me any extra money when I offer them "cute chick" and get "site broken" in return.
0
 
Dave BaldwinFixer of ProblemsCommented:
Ray, I notice you only list hosting companies that Have telephone support... something I consider a requirement also.  My favorite is Hurricane Electric but that's SSH shell access, no 'one-click' installations.
0
 
Julian MatzJoint ChairpersonCommented:
Good point :) If, however, Danica Patrick turned up on my doorstep instead of my browser window, I wouldn't care so much about "broken site"... Not for a while anyway.
0
 
CCSNVAuthor Commented:
Thank you all for the advice, I am going to try these out and will report back.
0
 
Ray PaseurCommented:
@DaveBaldwin, I have not use Hurricane Electric, but I have heard them well-recommended by others.  If you like them too, they must be good!
0
 
Dave BaldwinFixer of ProblemsCommented:
Hurricane Electric is good but it's command line operation which puts off a lot of people.  They answer the phone and they have very good connections to all the major networks.  They are also one of the PHP mirrors and  IPv6 specialists.  http://www.he.net/
0
 
CCSNVAuthor Commented:
Thank you all for the help. As soon as I added what Ray suggested on line 12, everything worked!
0
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

Join & Write a Comment

Featured Post

Cloud Class® Course: MCSA MCSE Windows Server 2012

This course teaches how to install and configure Windows Server 2012 R2.  It is the first step on your path to becoming a Microsoft Certified Solutions Expert (MCSE).

  • 4
  • 4
  • 4
  • +3
Tackle projects and never again get stuck behind a technical roadblock.
Join Now