Is it possible to create and use a MySQL database outside of my website host and link it to my website.
For example, using freehostia.com, my website is being hosted with one MySQL database to handle the WordPress Application installed. I want another database to use for SourceBans, and have it accessed at MyWebsiteName.com/bans, but freehostia.com only allows free users to have one database.
Is it possible to create another database somewhere else and use it on my website?
Yes, You can.
You can separate out your application server and the database server. But there are configurations that need to be done in order for such architecture to work. This is mostly done due to security and scalability.
Please kindly elaborate your requirement so that I can help you.
Other users already that yes you can, I want to show a simple approach on you gonna do it.
Simple when you are connecting to an external Database , you can use the mysql's server IP as your host when trying to connect using PHP.
For example in PHP:
$host = "192.182.0.124";
$use = "username"
$pass = "pass";
$db = "your db name"
$conn = new mysql ($host,$user,$pass,$db);
If your dababase is in the same server as your application, use localhost in $host or use the IP or host name of the database server if the server is external.
most PHP applications has a config file. database connection is mostly in the config file, for example, wp-config.php is the file WordPress use to store the database connection. Find out which file your php application is using to connect to database and change the database host to the IP of the external server.
Yes, it is pretty much possible and doable.
Related
Using phpmyadmin as my database software I have created mobile web app that uses php to contact the database. I am using phpmyadmin through the university server. My problem is I don't no how I would go about connecting this database to my web application from anywhere in the world. For example if I’m sending a picture to the database via my web application it doesn't have the right connection to phpmyadmin to work outside of the university environment. Can anybody shed some light on how I would go about this in terms of how to connect to phpmyadmin, does it need different credentials from when I’m using it in the university, and below is an example of how it is currently connecting:
$conn = mysql_connect('localhost','USERNAME','PASSWORD') ;
$db = mysql_select_db('B00556019');
Should I be contacting this database differently, like for example changing the localhost to something else? Also can PHP be used to contact the university phpmyadmin database and have my web application working from it? And sorry for the lack of knowledge and detail I'm very much below par with databases. If you need any more details to help understand better let me know. Thank you for your time.
Change your connection code as below :
$conn = mysql_connect('Server ip address','username','password') ;
$db = mysql_select_db('B00556019');
YOu need to change localhost with your server ip.
Note :
Most default installs of MySQL only listen to the local machine.
Look for the bind-address setting in my.cnf on the server, and make sure it's listening on the IP address you're targetting. You may also need to ensure skip-networking isn't switched on!
Alternatively (and less securely!) the following will set it up to listen on all addresses - local and remote:
bind-address = 0.0.0.0
Create a webservice and have your mobile app send data to that. Far more secure.
Then the webservice could write them to the database (which could then be on localhost). Webservice will just take queries write them to the database and provide responses over http back to your mobile app.
You also won't get firewall issues as it will all be over HTTP then.
i have been in a problem to connect to a sqlite database in remote host. I have already gone through alot of research on this, it seems not possible, but using rest api (building web services) can solve this problem. I can't use web services to interact with DB for my application.
Additional details,
is it possible to use path as http://192.168.0.6/computer_a/computer_a.sqlite ?? I have tried this but not working
my code
$db = new SQLite3($comAdb) or die('Unable to open database');
$comAdb -> http://192.168.0.6/computer_a/computer_a.sqlite
Please help
Thanks
No. You have to give a path on a file system.
You could use cURL to download the database, save it locally and then access it.
Can you create a file system mapping to the remote directory, where the second database resides?
Then you can just use ATTACH
I have set up a website with basic HTML/CSS files and would like to take that one step further and implement a database with some PHP to perform simple queries and whatnot.
My problem arose when I noticed while setting up the database and creating the PHP files that connect to the database (on my local machine), I used 'localhost' as an argument for mysql_connect. When I then went to drag and drop my newly created HTML/PHP files along with my database into FileZilla to upload the pages onto my remote server, there was a problem connecting to the database. I have a feeling that it is unhappy with the whole 'localhost' notion - yet I don't know what to change it to.
Currently, I am using this line of PHP code to connect to my remote database (which is all located in FileZilla-land).
$link = mysql_connect('localhost','Tommy','pass')
Also, as another quick question: does my remote server have its own phpMyAdmin page? And if so... how would one go about finding it? =D
I appreciate anyone who is able to assist me in my endeavors.
Thank you!!
Log on to your database server, check the details and obtain the correct server information such as server, username and password.
Once you change the server details you shoudl be ready to rock n roll. Edit post with the host name/server name and we may be able to find it for you.
You'll have a phpMyAdmin page where you're hosting the site. Check the membership area or cPanel.
You are right in that 'localhost' in mysql_connect needs to be different. 'localhost' is a textual representation of a loopback address AFAIK - it connects to the computer it is hosted on. As you have uploaded it to your server (a different computer) it is now trying to connect to a mysql server on the server host, instead of your home computer (which holds all the data).
To make this work you'd need to get your database onto the server you are now working from, OR depending on your home setup, point it to your local database.
Whether your host has MySQL/PHPMyAdmin available to you is another matter altogether. If they have MySQL it is probable but not definite that they have a phpmyadmin interface.
Contacting the server host will yield more information. If they have MySQL, it is probably as simple as getting the required details from them, and 'backing up' your SQL on your local server and uploading it to the new server (easily done with PHPMyAdmin)
TL;DR: The database you are trying to connect to doesn't exist on the server you're connecting from.
Newbie question. I have a project that need to access other web database using PHP. Is it possible?
for example:
I have a domain www.domain1.com with database1 and I have another domain www.domain2.com with database2 with different hosting. Can I access database1 from www.domain2.com which is also using database2?
Is it possible if it is the same hosting with 2 different domain?
Yes. In order to do that, just follow the other answers here.
But, in order to do things the right way, it is more recommendable to create some middleware between your web application and the remote database (e.g. SOAP, RESTful, or just raw ad-hoc XML). It will add security and decoupling.
You can connect to as many databases as many your application requires.
Get started with:
http://dev.mysql.com/doc/refman/5.0/en/connecting.html
Make sure port of domain2 allows authentication from domain1 (or you can keep it open for all, NOT RECOMMENDED).
If you are saying about JOINING databases then, so far I have worked on many projects where we had multiple databases on same server. So HOST was not an issue.
Yes, as long as the server port is open for PHP hosting domain .
It is possible if
the remote database user is accepting connections from local script
the mysql port 3306 from machine2 is open for machine1
Yeah, if you use MySql you have to set it to allow remote connections and then pass the ip/domain of the remote db in the mysql connect function
Yeah as long as you have a port open 80 should do, make sure you let the host know so they can allow you an account through.
if you can access other stuff outside your localhost you can just like this:
$conn2 = mysql_connect($otherhost, $otheruser, $otherpassword, true);
//the true at the end makes a new link
$query = mysql_query($your_query, $conn2);
this just send a query to the other database
I need help on creating a basic log-in page and registration page. I only know the basic stuff on php. And my boss told me to use the database he created online (phpmyadmin). So how do I connect the .php file I created to the online database? I have experienced connecting it to a database. But not the one that's online. Any help please? Thank you!
Firstly, PhpMyAdmin is not a database. It is a PHP based database admin tool to ease the management of databases so that you don't need to do the "boring" commandline interface stuff.
Assuming that it's actually just a MySQL database, then you can connect it using mysql_connect().
if you know how to connect it to the local database, it's always the same: you need a server address (localhost, IP or domain), database name, username and password.
read more here:
http://php.net/mysqli
http://php.net/mysql