Database Connect Godaddy - php

I have bought a Web Hosting on Godaddy. I worked on my website with WampServer and the following code worked good. Now, with Godaddy it doesn't work.
#mysql_connect('localhost', 'root', '');
#mysql_select_db('neiasite');
Can you help me please?
Thanks for reading.

In Godaddy, or any other shared hosting, you will not be given root user access to database. You need to create an user and password for your database.
This link will explain how.
https://support.godaddy.com/help/article/36/creating-mysql-or-sql-server-databases-for-your-hosting-account
And you need to use MySQLi to connect
$link = mysqli_connect("localhost","use_your_username","use_your_password","your_database_name") or die("Error " . mysqli_error($link));

Remember to import you existing database to godaddy from your localhost.
And i guess you should take a look at this tutourial on how to connect to godaddy mysql
http://www.prophoto.com/support/godaddy-mysql/

Hola! Thank you so very much for helping me.
I have successfully fixed it with this code:
mysql_connect("localhost", "username", "password")or die("cannot connect to server");
mysql_select_db("db_name")or die("cannot select db");
Source: http://www.phpeasystep.com/mysql/4.html.
Pce. (:
#Arun, #Andre, #Gopakumar Gopalan, #Djip

Related

How to connect to a remote computer running a sql database via php

I am running an apache webserver on a server on my local network.
I have a microsoft SQL server 2008 r2 database running on a different machine on the same network. My webserver is hosting a lot of pages, and are all fine and can be accessed locally and externally. However, when I try to connect to the SQL database using php, I get hit with the following error.:
Failed to connect to MySQL: No connection could be made because the target machine actively refused it.
I am at a total loss at this point as I have opened port 1433 and have spent hours trying to figure this out.
The code that I am using is a very basic connect script:
<?php
// Create connection
$con = mysqli_connect("mycomputer", "myname", "password", "my_db");
// Check connection
if (mysqli_connect_errno())
{
echo "Failed to connect to MySQL: " . mysqli_connect_error();
}
?>
If anyone can help, I would sincerely appreciate it as iIam about to give up on this project!!!
Thank you in advance.
As i understand - you use MS SQL , so you must use mssql_connect not as mysqli_connect
Check here
Cause its another database and another driver (extension ) using to connect

Cannot connect to MySQL database, socket error

I'm new to php, and while trying to make a connection on one of my pages to the database I set up on the phpMyAdmin page of my site.
I get this error:
"Database connection failed: Can't connect to local MySQL server
through socket '/tmp/mysql.sock' (46) (2002)"
I don't know what a socket is, or why it's trying to go to what looks like a temp file, so I don't even know where to being to troubleshoot this.
The code I'm using to make the initial connection is this:
<?php
define("DB_SERVER", "localhost");
define("DB_USER", "xxxx");
define("DB_PASS", "xxxx");
define("DB_NAME", "tester");
$connection = mysqli_connect(DB_SERVER, DB_USER, DB_PASS, DB_NAME);
// Test if connection occurred.
if(mysqli_connect_errno()) {
die("Database connection failed: " .
mysqli_connect_error() .
" (" . mysqli_connect_errno() . ")"
);
}
?>
I know I should have access to the MySQL databases, since I logged on and made them myself.
I previously set the page up by using WAMP on my computer, and everything worked fine.
It's just when I tried making it live on the site that I ran into this error.
Any help would be awesome!!
Try using 127.0.0.1 instead of localhost.
If that does not solve it, and you have root access to your server, try the following command
service mysql restart
To restart the mysql server.
The first option will probably work. Again, if you have root access to your server, you should change the mysql config to support sockets, since it's better than the TCP-ip connection.
After contacting my hosting service several times, it seems the error occurred because my hosting service recently changed their specifications and now uses "mysql" instead of "localhost" in the host and server fields. I had used "localhost" before with another host service, so I didn't think to change this, and the latest help articles on my host's website had not updated to reflect this.

Having trouble with connecting to MySQL database in php

I've made mysql.php file which contain codes to connect to my database.
However, i'm getting this error message over and over again.
Warning: mysql_connect() [function.mysql-connect]: Can't connect to MySQL server on 'localhost' (10061) in C:\CustomerData\webspaces\webspace_00290195\wwwroot\mysql.php on line 7
Warning: mysql_select_db() [function.mysql-select-db]: Can't connect to MySQL server on 'localhost' (10061) in C:\CustomerData\webspaces\webspace_00290195\wwwroot\mysql.php on line 8
Warning: mysql_select_db() [function.mysql-select-db]: A link to the server could not be established in C:\CustomerData\webspaces\webspace_00290195\wwwroot\mysql.php on line 8
Unable to select database
I've checked if my username, host, database, and password were misspelled, but they were all correct.
I've looked around the internet, but couldn't seem to find the right one for my problem.
My mysql.php file contains:
<?php
// Mysql settings
$user = "example_example";
$password = "example";
$database = "example_example";
$host = "localhost";
mysql_connect($host,$user,$password);
mysql_select_db($database) or die( "Unable to select database");
?>
I've changed my user, password and host name to "example".
I just couldn't find the solution for myself, and I need your kind help.
Thank you in advance.
Please try to find out the error by using mysql_error() function as follows :
mysql_connect($host,$user,$password) or die(mysql_error());
mysql_select_db($database) or die(mysql_error());
and then try to find the exact reason for the failure.
Warning: mysql_connect() [function.mysql-connect]: Can't connect to MySQL server on 'localhost' (10061)
here a list of questions you have to do when this error appears:
1.- is mysql running on the server?
1.1.- is mysql running on default port or in a custom port?
1.2 - is mysql accepting connexions (from localhost, from an ip...?
1.3 - your firewall is blocking mysql?
2.- the database exists on the server?
3.- the user:password have access to that database?
3.1- the user:password can log in from localhost, from an ip... from any place that mysql
is accepting?
I think I don't forget anything
Please check first that your mysql server is running properly.
Mysql settings
$user = "example_example";
$password = "example";
$database = "example_example";
$host = "localhost";
$cn=mysql_connect($host,$user,$password);
mysql_select_db($database,$cn);
Please try this it may work
I am not expert of php but this code is working perfectly in my website
if you are getting any error after applying this code then please inform me i will rty to solve the problem.
Thanks
You should provide the connection that need to use from database whle selecting database. Also use single quote instead of double quotes.
<?php
// Mysql settings
$user = 'example_example';
$password = 'example';
$database = 'example_example';
$host = 'localhost';
$link = mysql_connect($host,$user,$password);
mysql_select_db($database,$link) or die( "Unable to select database");
?>
Reference
You have to get the database information first. You posted this problem when you try to connect to your database in your website hosting, right?
So, go to your hosting control panel to get the MySQL database (and take note of where the database is stored on! Sometimes some hosting providers don't use "localhost". Instead, some of them may use 'serverXX.yourhostingprovider.tld' where XX means the server ID), and then change the corresponding variables with the value you've obtained from the hosting control panel.

Connecting mysql remotely via free host

I registered on 000webhost and I can connect to mysql db pages that are uploaded there via:
mysql_connect('localhost', 'user', 'pass') or die('Could not connect to database');
mysql_select_db('name') or die('Could not select database');
But it seems it does not allow connecting remotely.
Is there any free host which has mysql db and allows remote connections ?
try heliohost.orgI used it sometime back and they got good service as well.The only problem is the registration get filled too quickly
000webhost does not provide MySQL remote access for free accounts,
have a look, so either go for an upgradation
Or try http://www.freemysql.net for remote free mysql server, But again its free hence very slow,
mysql_connect('SQL**.FREEMYSQL.NET', 'USER', 'PASS') or die('Could not connect to database');
mysql_select_db('DBNAME') or die('Could not select database');
Do not use "localhost"

sftp connection

When I' m trying to connect Sftp from my joomla site
its not connecting:
$c = ftp_connect('ftp.xyz.com') or die("Can't connect");
ftp_login($c, 'username' , 'pwd') or die("Can't login");
in this case msg showing Can't connect
I also tried this code
$connection = ssh2_connect('ftp.xyz.com', 22);
if (!$connection) die('Connection failed');
in this case no error msg showing
Please help me, if there is a proper solution help me please.
Thanks
ftp_connect() uses FTP, not SFTP. They're very different. So if your host is providing only SFTP, then no, that function won't work! SFTP is explained in more detail here:
http://en.wikipedia.org/wiki/SSH_File_Transfer_Protocol
ssh2_connect() is the right connection method to use, which is why it's probably working. You can see all the SSH2 functions available in PHP here:
http://php.net/manual/en/ref.ssh2.php
You'll probably be most interested in ssh2_scp_recv() and ssh2_scp_send() (for getting and sending files).

Categories