Search code examples
phpdatabaseconnectiondatabase-connection

connection to db4free with php


i'm new here and doing some project,

how can i connect to my database in db4free.net from php, i have tried this

<?php

$host = "db4free.net/mainbookstore";
$user = "***";
$pass = "****";
$database = "mainbookstore";

$conn = mysql_connect($host, $user, $pass);
if ($conn) {
$buka = mysql_select_db ($database);
if (!$buka) {
die ("Database tidak dapat dibuka");
}
} else {
die ("Server MySQL tidak terhubung"); 
}

?>

but get error Such no host, but in my java use :

dataSource.setUrl("jdbc:mysql://db4free.net:3306/mainbookstore");

i can connect to my database. Thanks before :)


Solution

  • Most likely, it is the missing port. Try

    $host = "db4free.net:3306/mainbookstore"; 
    

    and it should work.