How to connect to database on freewebhostingarea? - php

Ok so i am making account system for my website. I am using freewebhostingarea as host. But i dont know what is servername(for connecting to database). Can you help me? Here is my code for connecting:
<?php
$servername = "";
$server = "root";
$password = "my password";
$dbName = "name";
$conn = mysqli_connect($servername, $server, $password, $dbName);
?>
I dont know what is $servername for freewebhoatingarea. Pls reply.

It's all the same actually . I want you to try this 4 steps
After you hit create databaase it will give you an option to name/rename your database so save that name to something like a notepad for your reference
(e.g) freehosting_db_(sampledatabase)
Next to that it that before you hit next on the creation of database kindly remember that password that you are going to make and like the name of the website save it to a notepad so you can remember the password
(e.g) xHsnaAXa123 -> password database
Mostly the server always localhost on SOME freehosting
The servername is automatically generated so look for it. It will be something like
(e.g) freehosting_db_(sampledatabase)_user
And to set that up
$servername = "freehosting_db_(sampledatabase)_user";
$server = "localhost";
$password = "xHsnaAXa123";
$dbName = "freehosting_db_(sampledatabase)";
PS: This is mostly how you setup a connection from your database to your server . But it is always depends on the the hosting that you are going to use . Godadday, Hostgator, 000webhostingapp, they are all alike on how setting it up .

Related

how to link mysql data base with my localhost website

I am beginner with creating websites
I have already created a website by html and ccs
and also i created the database by my sql queries
Now still link the database with my website in xampp server
But I have no idea how to do it
I search google i found one explanation that told me to create db_connection.php file in htdocs where my website files located and import my database file to myphp admin
I did all these steps
I don't know what is the next step
should i write any codes in each page code of my website or not
I hope someone help me
I will really thankful for him/her
In your db_connection.php you should write
$dbServername = "localhost"; //if you use xampp, it will be localhost
$dbUsername = "yourUsername"; //standart login is root
$dbPassword = "yourPassword"; //standart password is none, so leave it empty
$dbName = "yourDbName"; //place your db name here
$conn = mysqli_connect($dbServername, $dbUsername, $dbPassword, $dbName);
Now you are connected to your db. Include this file where you need to perform query's.

Link PHPMyAdmin MySQL databases to a PHP file

I'm running into an issue while trying to link a MySQL database to a PHP file.
Im trying to setup this PHP login system from Github and currently I'm trying to setup the dbconf.php file. This is the code where I'm trying to link the database to.
<?php
//DATABASE CONNECTION VARIABLES
$host = "localhost"; // Host name
$username = "user"; // Mysql username
$password = "password"; // Mysql password
$db_name = "22445671_login"; // Database name
//DO NOT CHANGE BELOW THIS LINE UNLESS YOU CHANGE THE NAMES OF
THE MEMBERS AND LOGINATTEMPTS TABLES
$tbl_prefix = ""; //***PLANNED FEATURE, LEAVE VALUE BLANK FOR NOW***
Prefix for all database tables
$tbl_members = $tbl_prefix."members";
$tbl_attempts = $tbl_prefix."loginAttempts";
The MySQL Database is named 22445671_login
I am just looking for a way to link the MySQL database to my document
Any help is greatly appreciated, thanks.
As put into my original question before it was removed. My website is hosted at at-space which comes with a PHPmyAdmin account linked to my website, I dont know how to link the MySQL database since I don't know if the username and password are just username and password. And I dont know if the host would be 1. My Website 2. atspace or 3. PHPMyAdmin
Where is your database hosted?
You might need to replace "localhost" with the hostname of your server:
$host = "localhost"; // Host name
Make sure you have the correct username and password
Make sure the user has the necessary permissions
Not sure if PMA has this feature, but SIDU has this feature:
<?php
$url = 'http://example.com/sidu54/conn.php'
.'?conn[host]='. $host
.'&conn[user]='. $username
.'&conn[pass]='. $password
// OR .'&conn[pass]='. $encryped_pass .'&conn[penc]=1'
.'&conn[dbs]='. $db_name
.'&conn[eng]=PDO_mysql'
.'&conn[char]=utf8'
.'&cmd=Connect'
.'&url=db.php'
.'&id=1,'. $db_name;
echo 'Click here to manage database';

I can't connect Joomla! remotely with MySQL

I have two hosting (1: IP 192.186.234.192 and 2: IP 74.116.84.169), and I have Joomla website files on hosting 1, Joomla mysql database on hosting 2, both hosting 1 and 2 have Cpanel administration.
I want run Joomla website on host1 by linked it remotely to mysql database on host 2
Steps that I made:
In hosting 2 added IP address for hosting 1 in (Remote MySQL).
In Joomla configuration.php file I have changed database section like:
var $host = '74.116.84.169';
var $user = 'artjour';
var $password = 'abc#123';
var $db = 'apuser';
I also have changed the host name by server name like:
var $host = 'servername.mydomainname.com';
But unfortunately:(, Could not connect to MySQL, please it's very important for me to know what's my wrong here.
Thanks in advance.
Use a small PHP script like this to see the error other then "Could not connect to MySQL":
<?php
$db_host = "123.456.789";
$db_name = "database";
$db_user = "user";
$db_pass = "password";
$db_table_prefix = "prefix_";
GLOBAL $errors;
GLOBAL $successes;
$errors = array();
$successes = array();
$mysqli = new mysqli($db_host, $db_user, $db_pass, $db_name);
GLOBAL $mysqli;
if(mysqli_connect_errno()) {
echo "Conn Error = " . mysqli_connect_error();
exit();
}
?>
in the hope that this may help someone I resolved the same situation.
I could access from server A and from command line mysql but I also could not connect my remote joomla database, the httpd server side needed selinux setsebool httpd_can_network_connect_db=1 to enable apache to connect to the remote database.
You probably have to allow remote SQL connection on server2 with Cpanel :
http://www.liquidweb.com/kb/enable-remote-mysql-connections-in-cpanel/

host is not allowed to connect to this server

quick mysql question.
I'm new at php/mysql and followed a tutorial(php/mysql for dummies) so I don't really know what I did wrong or if the tutorial is wrong.
I have a file, "database_connections.inc", that looks like this:
<?php
$user = "username";
$host = "host";
$password = "password";
$database = "database";
?>
With the actual credentials not included for obvious reasons.
Then in another file, login.php, I have:
include("database_connections.inc");
$cxn = mysqli_connect($host,$user,$password,$database)
or die("Query died: Couldnt connect to server.");
I get an error message with the "or die" text, accompanied by a warning:
host xxxxx.000webhost.com is not allowed to connect to this mysql server in....
Why not? I'm sure my credentials are all correct.
I've read in a few places to run some shell statements...but can't really do that, I'm on Windows.
I'm using phpMyAdmin, so hopefully I can do something from there?
Open "database_connections.inc" and change it to look like this:
<?php
$user = "root";
$host = "localhost";
$password = "";
$database = "test";
?>
MySQL is by default configured to work with localhost (or 127.0.0.1), in order to allow "host xxxxx.000webhost.com" as host, open phpMyAdmin and select "SQL" and execute this query;
GRANT ALL ON your_database_name.* TO your_user#your_host_xx.xxx.xx.xx IDENTIFIED BY 'your_password';
Go into PHPMyAdmin, and edit your user.
Under Login Information, there should be an option for "Host"- try adding xxxxx.000webhost.com.

Can't get my PHP document to connect to my xampp server

I am very new to php, and am sorry if this question turns out to be too vague, but if there is any other information that you need from me let me know.
Anyway, basically what my problem is I have some simple php code that should call die() if it can't connect to the xampp server I have set up, however, even if I put in invalid info for the server or user it prints Successful. I really don't know where to go with this, so if anyone has any suggestions that would be great.
<?php
$dbhost = 'localhost';
$dbuser = 'root';
$dbpass = '';
if ( !mysql_connect($dbhost, $dbuser, $dbpass) )
{
die(mysql_error());
}
else
echo 'Succesful';
?>
Ok for some reason it was just not working with the root user, so I created a new user who required a password and apparently that connected like it was supposed to. Thanks everyone for the answers.
Your code is correct pistolpete333. For your root user issue, that your not able to connect with root user you can check below file for your phpmyadmin configuration
C:\wamp\apps\phpmyadmin3.5.1\config.inc.php.
In above file you can check your host, username and password of phpmyadmin.
I have found that when trying to connect php to an xampp server there are usually only a few things that could cause the issue you are having.
1. mySQL service is not running
2. no specific database is selected to try to access
3. user does not exist in phpmyadmin.
When you pick a user to connect php to mySQL with you should always make sure that a password is set, that is usually the thing people miss. You can use root if you create another instance of it in the user list and require a password, or you can add a password to the root user already in the list, but the best option is to create a new custom user that only has access to the database you want to access with your php and make sure it has a password required. (make sure any user you use can connect with localhost; root can by default and I think most newly created users can as well).
Below is the php I use for websites I design that need php to access a DB.
<?php
// This configures the variables for database access
$dbhost = 'localhost';
$dbuser = '????';
$dbpass = '????';
$dbname = '????';
// This will connect to the server and then the correct database
$conn = mysql_connect($dbhost, $dbuser, $dbpass) or die ('Error connecting to mysql');
mysql_select_db($dbname);
?>
This is working because you have specified valid username, host and password to mysql. If you specify wrong password, you get mysql error. This code works and connects to the mysql server though you have not selected any database.
Try this code instead
<?php
$dbhost = 'localhost';
$dbuser = 'root';
$dbpass = '';
$link = mysql_connect($dbhost, $dbuser, $dbpass);
if (!$link) {
die('Not connected : ' . mysql_error());
}
// make foo the current db
$db_selected = mysql_select_db('foo', $link); //foo is your database name
if (!$db_selected) {
die ('Can\'t use foo : ' . mysql_error());
}
?>

Categories