Solved

MySql Connection

Posted on 2011-02-18
19
420 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
19 Comments
 
LVL 142

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 100 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
 
LVL 82

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 100 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 108

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 108

Accepted Solution

by:
Ray Paseur earned 300 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
Enabling OSINT in Activity Based Intelligence

Activity based intelligence (ABI) requires access to all available sources of data. Recorded Future allows analysts to observe structured data on the open, deep, and dark web.

 
LVL 82

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 108

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 82

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 108

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 82

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

How to run any project with ease

Manage projects of all sizes how you want. Great for personal to-do lists, project milestones, team priorities and launch plans.
- Combine task lists, docs, spreadsheets, and chat in one
- View and edit from mobile/offline
- Cut down on emails

Join & Write a Comment

Suggested Solutions

Developers of all skill levels should learn to use current best practices when developing websites. However many developers, new and old, fall into the trap of using deprecated features because this is what so many tutorials and books tell them to u…
Password hashing is better than message digests or encryption, and you should be using it instead of message digests or encryption.  Find out why and how in this article, which supplements the original article on PHP Client Registration, Login, Logo…
Explain concepts important to validation of email addresses with regular expressions. Applies to most languages/tools that uses regular expressions. Consider email address RFCs: Look at HTML5 form input element (with type=email) regex pattern: T…
The viewer will learn how to count occurrences of each item in an array.

760 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

Need Help in Real-Time?

Connect with top rated Experts

17 Experts available now in Live!

Get 1:1 Help Now