I have an online database and what I need to do is to fetch data from it and save to my local database(localhost). I tried adding remote mysql database cause it said it is needed(I added the IP address of my local computer), I dont know if its right. The problem is it gives me an error
"arning: mysql_connect() [function.mysql-connect]: Can't connect to MySQL server on '10.24.168.85' (4) in /home/umalert/public_html/server/_includes/connection.php on line 18
Database connection failed:".
For now I have this connection script:
// create database connection
$connection_local = mysql_connect('x.x.x.x:3306', 'xxx', 'yyy');
if(!$connection_local) {
die ("Database connection failed: " . mysql_error());
}
// selece database to use
$db_select_local = mysql_select_db('umalert_db', $connection_local);
if(!$db_select_local) {
die("Database connection failed: ". mysql_error());
}
Hope you can help me with this. Thank you.
you should export your data from one database and import to another one.
Related
Hello I've been making a site on my local server and I finished it so I'm moving everything over to my live server. I've made a database in phpmyadmin on it and I would like to connect to it. I feel like I have the wrong inputs though because it gives me this error.
This is my code for my database connection.
<?php
return $conn = mysqli_connect('localhost', 'gener105_nate', '(Password)', 'user_data');
if (!$conn) {
die("Connection Failed: " . mysqli_connect_error);
}
I didn't actually enter password I just think I shouldn't show it anyway I think I just have something mixed up since I'm new at this.
Oh and the database is located within a database grouping should i input the path to it?
You need to tell it to connect to gener105_user_data instead of just user_data
return $conn = mysqli_connect('localhost', 'gener105_nate', '(Password)', 'gener105_user_data');
I am trying to connect to my 000webhost MySQL database but it can't connect
Here is my PHP:
<?php
$db = new mysqli("mysql9.000webhost.com", "a9012103_msg", "msg123", "a9012103_msg");
if($db->connect_error) {
die("Couldn't connect to DB");
} else {
die("Connection successful");
}
?>
I have all of the correct information. Here is the information for the database
MySQL Database --- MySQL User --- MySQL Host
a9012103_msg --- a9012103_msg --- mysql9.000webhost.com
I assume that the database automatically adds in the user after I create it. I have tried using localhost but that doesn't work either.
My website is devconnect.comxa.com
It seems to be a blank space after the hostname:
"mysql9.000webhost.com "
I just started programming in php and would like to ask a question about the database selection code for mysql in the php coding.
I used phpmyadmin to create a database "admin" when in phpmyadmin I click on privileges and see the name as"admin#127.0.0.1". I created a connection to the database using this code in PHP:
<?php $connection = mysqli_connect("127.0.0.1", "admin", "admin123");
if (!$connection)
die("Database connection failed:" . mysqli_error());
and now i want to select the tables in the database I use this command:
$selected = mysqli_select_db("admin", $connection);
if (!$selected)
{
die('Database selection failed:' .mysqli_error());
}
?>
I know it connects because when only using the connection command when opening my broswer I can see the header i put in html, but I get an error with the selection command and cannot continue.
Warning: mysqli_select_db() expects parameter 1 to be mysqli, string given in C:\Program Files\EasyPHP-DevServer-13.1VC11\data\localweb\projects\databaZE.php on line 6##
Warning: mysqli_error() expects exactly 1 parameter, 0 given in C:\Program Files\EasyPHP-DevServer-13.1VC11\data\localweb\projects\databaZE.php on line 8
Database selection failed:
Firstly is there a problem with the way I wrote my database name thats why it cannot connect and giving me error msg's?I used 127.0.0.1 as database, admin#127.0.0.1 but still same msg. I tried both mysql and mysqli but it doesnt seem to work also.
Edit: first time user sorry am a little confused with inputting code.
You have them the wrong way around,
$selected = mysqli_select_db("admin", $connection);
should be
$selected = mysqli_select_db($connection, "admin");
And
die('Database selection failed:' .mysqli_error());
should be
die('Database selection failed:' .mysqli_error($connection));
I have created a HTML form and im trying to link it to a PHP myadmin database.But it says
Warning: mysql_connect(): A connection attempt failed because the connected party did not
properly respond after a period of time, or established connection failed because
connected host has failed to respond. in C:\xampp\htdocs\form.php on line 8 Could not
connect:A connection attempt failed because the connected party did not properly respond
after a period of time, or established connection failed because connected host has failed
to respond.I dont know why thats happening.This is my code below,
<?php
define('DB_NAME','Registernewaccount');
define ('DB_USER' ,'root');
define('DB_PASSWORD','12345');
define('DB_HOST','localhost');
$link = mysql_connect('DB_HOST','DB_USER','DB_PASSWORD');
if (!$link){
die('Could not connect:' . mysql_error());
}
$db_selected = mysql_select_db(DB_NAME,$link);
if(!$db_selected){
die('Can\'t use' .DB_NAME .':' . mysql_error());
}
mysql_close();
?>
Can you please help me
Considering the fact i know nothing about your setup. And assuming you have a database server up and running. It's probably that you have quoted the constants in the mysql_connect call
Change
$link = mysql_connect('DB_HOST','DB_USER','DB_PASSWORD');
to
$link = mysql_connect(DB_HOST,DB_USER,DB_PASSWORD);
I am trying to insert data to a web site from the code of another web site. How can I use the mysql_connect() command for that. Can I use the IP address of the first web site in the second web site code?
Please help me
Yes, you can use a remote MySQL server with mysql_connect(). Use mysql_connect() according to the PHP manual (http://php.net/manual/de/function.mysql-connect.php) and use your server's IP as $server. However, make sure the MySQL port is accessible from remote on the MySQL server (port 3306).
For inserting data in the database you need to connect the database
Selecting DATABASE
you need to just connect the server on which the db exist in which we are inserting
<?php
$link = mysql_connect('ip or server of the db in which inserting', 'mysql_user', 'mysql_password');
if (!$link) {
die('Not connected : ' . mysql_error());
}
// make myDB the current database
$db_selected = mysql_select_db('myDB', $link);
if (!$db_selected) {
die ('Can\'t use myDB: ' . mysql_error());
}
?>
for inserting records in another website , you need to just connect the server and DB of that particular website, and fire Queries.
let me know if more..