Solved

MySql Connection

Posted on 2011-02-18
19
447 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 4
  • 4
  • 4
  • +3
19 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 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
Revamp Your Training Process

Drastically shorten your training time with WalkMe's advanced online training solution that Guides your trainees to action.

 
LVL 83

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 110

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 110

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
 
LVL 83

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 110

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 83

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 110

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 83

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

Free Tool: SSL Checker

Scans your site and returns information about your SSL implementation and certificate. Helpful for debugging and validating your SSL configuration.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Question has a verified solution.

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

This article discusses how to implement server side field validation and display customized error messages to the client.
Containers like Docker and Rocket are getting more popular every day. In my conversations with customers, they consistently ask what containers are and how they can use them in their environment. If you’re as curious as most people, read on. . .
The viewer will learn how to create and use a small PHP class to apply a watermark to an image. This video shows the viewer the setup for the PHP watermark as well as important coding language. Continue to Part 2 to learn the core code used in creat…
This tutorial will teach you the core code needed to finalize the addition of a watermark to your image. The viewer will use a small PHP class to learn and create a watermark.

688 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