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 :)
Most likely, it is the missing port. Try
$host = "db4free.net:3306/mainbookstore";
and it should work.
Related
How to connect Oracle database in php using xampp?
Is it right?
$servername = "localhost";
$username= "username";
$password= "password";
$dbname = "db";
$conn= new mysqli($servername,$username,$password,$dbname);
// check connection
if($conn->connect_error){
die("connection Failed:".$conn->connection_error);
}
Try This
Review the code in $HOME/public_html/connect.php
<?php
// Create connection to Oracle
$conn = oci_connect("phphol", "welcome", "//localhost/orcl");
if (!$conn) {
$m = oci_error();
echo $m['message'], "\n";
exit;
}
else {
print "Connected to Oracle!";
}
// Close the Oracle connection
oci_close($conn);
?>
The oci_connect() function contains the username, the password and the connection string. In this case, Oracle's Easy Connect connection string syntax is used. It consists of the hostname and the DB service name.
The oci_close() function closes the connection. Any standard connections not explicitly closed will be automatically released when the script ends.
$username="OE";
$password="OE";
$db="(DESCRIPTION =
(ADDRESS = (PROTOCOL = TCP)(HOST = localhost)(PORT = 1521))
(CONNECT_DATA =
(SERVER = DEDICATED)
(SERVICE_NAME = XE)
)
)";
$connection = oci_connect($username, $password, $db);
if (!$connection) {
$e = oci_error();
echo htmlentities($e["message"]);
}
Try this just make an query request with this function
mysqli_query($connectionhandler, $sqlquery);
I have an issue with PHP script not connecting to MySQL database. Below code always generates error:
$dbconn = #mysql_connect('SFDC1', '<username>', '<password>');
if (!$dbconn)
{
die('Error connecting to DB!');
}
There is no issue if I connect to the database using MySQL workbench with same credentials. Issue only occurs during the communication between PHP and MySQL.
Any help on debug of this issue?
Try this one;
$dbhost = "localhost";
$dbuser = "username";
$dbpass = "pass";
$dbname = "DBname";
if(!#mysql_connect($dbhost,$dbuser,$dbpass)) {
echo "Cannot connect";
die();
} else
mysql_select_db($dbname);// or report();
Use this code to connect mysql.
<?php
$dbconn = mysql_connect('localhost', 'mysql_user', 'mysql_password');
if (!$dbconn ) {
die('Could not connect: ' . mysql_error());
}
?>
I am having problems connecting with a database using a php form. I have created a separate file for php database parameters.
<?
$db_username = "username";
$db_password = "password";
$db_name = "db";
$db_host = "host";
?>
Include statement
include "db_data.php";
This is my connection String
$dblink = $Database->connect($db_username, $db_password, $db_name, $db_host);
This is my database class
<?php
class Database{
var $dblink;
var $query_error;
var $username;
var $password;
var $host;
var $database;
function connect ($username, $password, $dbname, $host) {
$this->dblink = mysql_connect($host, $username, $password);
mysql_select_db($dbname);
if($this->dblink == ""){
echo "Error connecting to database $database<Br>";
return -1;
}else{
return $this->dblink;
}
}
function disconnect(){
mysql_close($this->dblink);
}
}
?>
I haven't changed any of my connection parameters. Will starting again mysql server solve the problem ??
Thanks Jose
A better way to connect to a database is this
mysqli_connect("database ip", "database name", "username for database", "password");
Try that and place it in a file named connection.php and put the code above in a var like such :
$conn = mysqli_connect("database ip", "database name", "username for database", "password");
Then include the file in your PHP files so there's no need to re-write this in every file
Include("connection.php");
So I wanted to install an acp on my homepage. I uploaded all needed files on my webserver (I use FileZilla Client) and opened phpMyAdmin with xampp.
It connects the database but then it says
"Database does not exist."
I'm fairly new to working with phpMyAdmin and mySQL as well.
this is what my db.php looks like:
<?php
$host = "localhost"; // database server
$user = "akichuchan"; // db username
$pw = "cherryjuice"; // db password
$db = "acp"; // db name
$link = mysql_connect($host, $user, $pw, $db) or die ("No connection possible.");
mysql_select_db($db, $link) or die ("Database does not exist.");
?>
What did I do wrong?
Thanks in advance. :)
Try the below working code:
<?php
$host = "localhost"; // database server
$user = "akichuchan"; // db username
$pw = "cherryjuice"; // db password
$db = "acp"; // db name
$link = mysql_connect($host, $user, $pw) or die ("No connection possible.");
mysql_select_db($db, $link) or die ("Database does not exist.");
?>
NOTE: Don't use " mysql_ ". Better to use " PDO or Mysqli_ " ( safe and secure ) .
Keep getting same error message
(Warning: mysql_connect() [function.mysql-connect]: Can't connect to local MySQL server through socket '/var/lib/mysql/mysql.sock' (2) in /home/content/00/7882800/html/Connections/dueslogin.php on line 27
Unable to connect to database! Please try again later.)
<?php
//Variables for connecting to your database.
//These variable values come from your hosting account.
$hostname = "TarHeelsDues.db.7882800.hostedresource.com";
$username = "TarHeelsDues";
$dbname = "TarHeelsDues";
//These variable values need to be changed by you before deploying
$password = "************";
$usertable = "DuesLogin";
$yourfield = "your_field";
//Connecting to your database
mysql_connect($hostname, $dbname, $password) OR DIE ("Unable to
connect to database! Please try again later.");
mysql_select_db($TarHeelsDues);
//Fetching from your database table.
$query = "SELECT * FROM $usertable";
$result = mysql_query($query);
if ($result) {
while($row = mysql_fetch_array($result)) {
$name = $row["$yourfield"];
echo "Name: $name<br>";
}
}
?>
change the mysql_connect line to
mysql_connect($hostname, $username, $password) OR DIE ("Unable to
connect to database! Please try again later.");
mysql_select_db($dbname);
A little mistake on there, you have to use $username not $dbname in mysql_connect.
mysql_connect($hostname, $username , $password) OR DIE ("Unable to
connect to database! Please try again later.");
mysql_select_db($TarHeelsDues);
The correct syntax should be like this:-
mysql_connect($hostname, $username , $password) OR die ("Unable to connect with the server");
mysql_select_db($TarHeelsDues) or die('Cannot connect with the database!');