How to connect to a Database on a Webserver

General discussions related to php

Moderators: macek, egami, gesf

New php-forum User
New php-forum User
Posts: 2
Joined: Sun Nov 03, 2013 7:22 am

How to connect to a Database on a Webserver

Postby rallepralle » Sun Nov 03, 2013 7:33 am


I'm using Win 7 and mySQL-DB. With XAMPP I'm already able to access a local DB on my computer. But how do I access a DB on an online Webserver?

This is the code I'm able to access my DB offline (localhost):

Code: Select all

    $inputuser = mysql_real_escape_string($_POST['user']);
    $inputpass = $_POST['pass'];


    $connect = mysql_connect("localhost", $user, $password);
    @mysql_select_db($database) or ("Database not found");

    $query="SELECT * FROM User WHERE UserName='$inputuser'";
    $querypass="SELECT * FROM User WHERE Password= '$inputpass'";




/*  echo $inputpass;
    echo "server-user: ";
    echo $serveruser;
    echo "server: ";
    echo $serverpass;
*/  if ($serveruser&&$serverpass){
        if (!$result){
            die("Username or passwor is invalid");

        if ($inputpass==$serverpass){


Now I want to do the very same with a DB on a "real" webserver. What do I have to change in the code above?
For this case, let's assume these:
My provider:
Location of my DB:
My Database name: DBreal
The username to my Database: DBrealName
The password to my Database: DBrealPassword

I tried this:
I replaced "localhost" with ""
I assigned "$database" with "DBreal"
I assigned "$user" with "DBrealName"
I assigned "$password" with "DBrealPassword"

....but I could only retrieve the value for $serverpass. The value for $serveruser is always empty. Could you please point out my mistake? Thanks in advance.

Return to “PHP General”

Who is online

Users browsing this forum: No registered users and 1 guest