?
Solved

MySql Connection

Posted on 2011-02-18
19
Medium Priority
?
483 Views
Last Modified: 2012-05-11
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
Comment
Question by:CCSNV
  • 4
  • 4
  • 4
  • +3
17 Comments
 
LVL 143

Expert Comment

by:Guy Hengel [angelIII / a3]
ID: 34927209
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
 
LVL 4

Assisted Solution

by:andreizz
andreizz earned 400 total points
ID: 34927271
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
 

Author Comment

by:CCSNV
ID: 34927932
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
Independent Software Vendors: We Want Your Opinion

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

 
LVL 84

Expert Comment

by:Dave Baldwin
ID: 35002327
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
 
LVL 21

Assisted Solution

by:Julian Matz
Julian Matz earned 400 total points
ID: 35002361
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
 
LVL 111

Expert Comment

by:Ray Paseur
ID: 35002586
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
 
LVL 111

Accepted Solution

by:
Ray Paseur earned 1200 total points
ID: 35002597
And on line 12, you might want to have this:

$db_host = "connect.godaddy.com";
0
 
LVL 21

Expert Comment

by:Julian Matz
ID: 35002831
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
 
LVL 84

Expert Comment

by:Dave Baldwin
ID: 35003055
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
 
LVL 21

Expert Comment

by:Julian Matz
ID: 35003125
I think what Ray meant to say was that opening a persistent MySQL connection might not be the best option, depending on.
0
 
LVL 111

Expert Comment

by:Ray Paseur
ID: 35003260
@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
 
LVL 84

Expert Comment

by:Dave Baldwin
ID: 35003350
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
 
LVL 21

Expert Comment

by:Julian Matz
ID: 35003392
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
 

Author Comment

by:CCSNV
ID: 35008348
Thank you all for the advice, I am going to try these out and will report back.
0
 
LVL 111

Expert Comment

by:Ray Paseur
ID: 35009261
@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
 
LVL 84

Expert Comment

by:Dave Baldwin
ID: 35009447
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
 

Author Closing Comment

by:CCSNV
ID: 35021037
Thank you all for the help. As soon as I added what Ray suggested on line 12, everything worked!
0

Featured Post

NEW Veeam Backup for Microsoft Office 365 1.5

With Office 365, it’s your data and your responsibility to protect it. NEW Veeam Backup for Microsoft Office 365 eliminates the risk of losing access to your Office 365 data.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

It’s a season to be thankful, and we’re thankful for users like you who engage on site, solve technology problems, and network with others in the industry. What tech are we most thankful for? Keep reading.
The title says it all. Writing any type of PHP Application or API code that provides high throughput, while under a heavy load, seems to be an arcane art form (Black Magic). This article aims to provide some general guidelines for producing this typ…
In this video, Percona Solution Engineer Dimitri Vanoverbeke discusses why you want to use at least three nodes in a database cluster. To discuss how Percona Consulting can help with your design and architecture needs for your database and infras…
In this video, Percona Solutions Engineer Barrett Chambers discusses some of the basic syntax differences between MySQL and MongoDB. To learn more check out our webinar on MongoDB administration for MySQL DBA: https://www.percona.com/resources/we…
Suggested Courses
Course of the Month14 days, 11 hours left to enroll

840 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question