Warning: mysqli_connect(): (HY000/1049): Unknown database 'art_gallery'
The database art_gallery is correctly imported and username is root, password is ``
<?php
$link=mysqli_connect("localhost","root","","art_gallery");
if(mysqli_connect_error())
{
echo "Connection error".mysqli_connect_error();
exit;
}
Normally in this type of error there are two possibilities.
First is that there are some Spelling errors.
or
Secondly you have different servers installed on your machine.
Mostly it would be due to second cause, thus to identify those servers uniquely, you have to specify the port number in the localhost when connecting via mysql connect statement
Try
mysqli_connect(“localhost:3308”,″root”,””,”dbname”) (default is 3306) it can be changed.
The port number can be checked in the phpmyadmin at top center of panel as something like server:3308
I think you can use new mysqli() function instead of mysqli_connect() function. Hope I could help you.
Related
I've read many questions similar to this but none of the answers have been relevant to me. I'm trying to access a SQL server using PHP. Both the SQL server and PHP are running on my Windows 10 machine. Here is my PHP code (the username and password are arbitrary):
$connection = mysqli_connect('127.0.0.1', 'hmuuser', 'password');
This causes the following error:
PHP Warning: mysqli_connect(): (HY000/2002): No connection could be made because the target machine actively refused it.
Here is my connection using MSSMS (which is successful):
EDIT:
I was able to solve my problem using this link: http://blog.citrix24.com/configure-sql-express-to-accept-remote-connections/
Using this link I enable SQL Browser, and set a static port to connect to SQL server with. However, I'm presented with a new error:
PHP Warning: mysqli_connect(): MySQL server has gone away in C:\HMUAPI\Index.php on line 7
PHP Warning: mysqli_connect(): Error while reading greeting packet. PID=9920 in C:\HMUAPI\Index.php on line 7
PHP Warning: mysqli_connect(): (HY000/2006): MySQL server has gone away in C:\HMUAPI\Index.php on line 7
My code has been changed to the following to cause this error: $connection = mysqli_connect('127.0.0.1:1434', 'hmuuser', 'password');
Add a database name
$connection = mysqli_connect('127.0.0.1', 'hmuuser', 'password','dbname');
Also here is suggest - Actively refused it" means that the host sent a reset instead of an ack when you tried to connect. It is therefore not a problem in your code. Either there is a firewall blocking the connection or the process that is hosting the service is not listening on that port. This may be because it is not running at all or because it is listening on a different port.
I guess the problem is, that you use MySQLi to connect to a MSSQL server.
You should use the correct MSSQL extension instead.
Microsoft published their SQL-Server for PHP driver on GitHub: https://github.com/Microsoft/msphpsql
Or you use the older extension which is documented in the PHP manual: http://de2.php.net/manual/en/book.mssql.php
And at least you can set up ODBC.
One of them should resolve your problem.
Whenever I try to run a php script on my website hosted by hostgator, I get this error:
Warning: mysql_connect() [function.mysql-connect]: Unknown MySQL server host 'pieboy13_(user name)' (1) in /home/pieboy13/public_html/quigley/WebContent/Scripts/register.php on line 6
Error: Could not connect to server. Error Unknown MySQL server host 'pieboy13_(user name)' (1)
Where (Username) is my username.
What could cause this?
You are triying to connect to your username! Check your configuration for server url and make sure it points to your mysql server.
Things that can cause this:
You are using the wrong hostname for the mysql server.
Looks like you might have put your database or username into the server argument.
Okay when I go to my web page I get the following error below but when I reload the page everything is okay and is displayed fine. What exactly is the problem and how can I fix it?
ERROR.
Warning: mysqli_connect() [function.mysqli-connect]: (HY000/2005): Unknown MySQL server host
MySQL code.
$mysqli = mysqli_connect("example.com", "avd", "password", "avd");
Server/Port combination is invalid, can't be resolved, or port is bad.
I keep getting the error below once in a while and then it goes away everything works fine. I was wondering how can I correct this problem? And can someone tell me what in hell is causing this problem?
Error.
mysqli_connect() [function.mysqli-connect]: (HY000/2005): Unknown MySQL server host
The error above points to the code below.
$mysqli = mysqli_connect("i.db.8473545.hostedresource.com", "i", "password", "i");
You're probably on a shared hosting environment with an external MySQL server. The error message hints on DNS problems resolving "i.db.8473545.hostedresource.com".
As a temporary fix, find out the IP "i.db.8473545.hostedresource.com" points to and use the IP adress as host name for mysql_connect(). See if you still get the error afterwards.
This might be ridiculously easy for you but I've been struggling with this for an hour... :(
<?php
$connect = mysql_connect("localhost:8080", "root", "mypassword");
echo($connect);?>
This is the code that I'm trying to run - you can see that I'm using 8080 as my port number and, of course, I have HTML codes as well.
However, it gives me the following error messages whenever I try to open the PHP file:
Warning: mysql_connect() [function.mysql-connect]: MySQL server has gone away in C:\wamp\www\php_sandbox\index.php on line 2
Warning: mysql_connect() [function.mysql-connect]: Error while reading greeting packet. PID=4932 in C:\wamp\www\php_sandbox\index.php on line 2
Warning: mysql_connect() [function.mysql-connect]: MySQL server has gone away in C:\wamp\www\php_sandbox\index.php on line 2
I don't know... what's wrong with this? Is it because of the port number?
Change localhost:8080 to localhost:3306.
Try opening Port 3306, and using that in the connection string not 8080.
Just Change the Connection mysql string to 127.0.0.1 and it will work