OVH Community, your new community space.

SQL host connection?


Neil
17-03-2011, 13:00
Quote Originally Posted by mercjim
localhost will do it will it? I have to admit, thats one I didnt try!
Localhost will not work as the databases are on different servers, you should use the hostname supplied in the email or in the OVH Manager.

mercjim
17-03-2011, 08:25
localhost will do it will it? I have to admit, thats one I didnt try!

freshwire
16-03-2011, 21:58
Quote Originally Posted by mercjim
What I am having difficulty with is knowing what I need to use connection string wise to connect to my DB from within PHP. I cant seem to get it right! I've had a scout on these forums and on OVHs documentation to no avail.
Go back to phpMyAdmin. The server hostname and port should be listed there.

YouWhat
16-03-2011, 20:34
$myServer = "localhost";
$myUser = "your_name";
$myPass = "your_password";
$myDB = "examples";

//connection to the database
$dbhandle = mssql_connect($myServer, $myUser, $myPass)
or die("Couldn't connect to SQL Server on $myServer");

//select a database to work with
$selected = mssql_select_db($myDB, $dbhandle)
or die("Couldn't open database $myDB");

//declare the SQL statement that will query the database
$query = "SELECT id, name, year ";
$query .= "FROM cars ";
$query .= "WHERE name='BMW'";

//execute the SQL query and return records
$result = mssql_query($query);

$numRows = mssql_num_rows($result);
echo "

" . $numRows . " Row" . ($numRows == 1 ? "" : "s") . " Returned

";

//display the results
while($row = mssql_fetch_array($result))
{
echo "
  • " . $row["id"] . $row["name"] . $row["year"] . "
  • ";
    }
    //close the connection
    mssql_close($dbhandle);
    ?>
    Above is example with some example code in there to pull data from a database, Hope this helps and answers your question

    mercjim
    16-03-2011, 18:19
    Hi there!

    Not sure if this is the right place to ask this, but I have a bit of a query I hope someone can answer. I am embarking on a bit of self-taught PHP lark and have some shared hosting with OVH with which to do this. I have a SQL database with OVH and have managed to set it up and connect to it with phpMyAdmin and create new tables and such forth.

    What I am having difficulty with is knowing what I need to use connection string wise to connect to my DB from within PHP. I cant seem to get it right! I've had a scout on these forums and on OVHs documentation to no avail.

    Can someone help this PHP virgin?

    Cheers,
    Jim