We just have a transfer from old Windows Server, to the new Windows Server 2012.
After that transfer new XAMPP was installed, and I recognized, that mssql_connect was discountinued some time ago. So I checked that last version when it was supported was 5.2.
So I reinstalled XAMPP for older one but I still can't make it work.
I am getting error:
Warning: mssql_connect() [function.mssql-connect]: Unable to connect to server: SERVER/SQLEXPRESS in F:\xampp_php5.2\htdocs\open_db.php on line 2
Error!
My file looks like this:
<?php
$link = mssql_connect("SERVER/SQLEXPRESS","login", "pass") or die("Error!");
mssql_select_db("dbinet") or die("DB not exist");
echo 'success';
?>
I can login to this server (SERVER/SQLEXPRESS) using login and pass directly by SQL Server Managment Studio, but can't by webpage...
Any idea where is a problem?
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.
I have a php website hosted in 1and1.com, but when I connect to our local server database(windows server 2012 and sql server 2012) it gives me no luck, it gives me this error:
Call to undefined function sqlsrv_connect() in dbconn.php on line 9.
here's my database connection:
<?php
$serverName='xxx.xxx.00.xx'; //<-- should I include PORT here?
$connectionInfo=array(
'Database'=>'DBName',
'UID'=>'userName',
"PWD"=>'Password');
$conn = sqlsrv_connect($serverName,$connectionInfo); //<-- line 9 here
if($conn){
//echo 'Connection Established!<br />';
}else{
//echo 'Connection Failed!<br />';
die(print_r(sqlsrv_errors(),TRUE));
}
?>
Actually, I'm confused what to use.. like should I use IIS here or other procedures but for development, I used XAMPP to test my website.
I'm new with this kind of stuff, so if you can provide me some step by step articles for this is much more appreciated.
Thanks in advance!
From the manual:
The SQLSRV extension requires that the Microsoft SQL Server 2012 Native Client be installed on the same computer that is running PHP.
Verify that is installed on your server.
I am using PHP , I want to connect to remote server in SFTP, but the website said:
Fatal error: Call to undefined function ssh2_connect() in D:\xampp\htdocs\dive\database.php on line 9
Can you tell me in detail how to do this? I tired
<?php
$connection = ssh2_connect('ftp.server.com', 22);
if (ssh2_auth_password($connection, 'username', 'password'))
echo "Authentication success";
else
echo "Authentication failure";
?>
But it doesn't work.
After I connect to the server, is there a difference if I want to insert some data to the table in it? Which function should I use?
Have you installed / verified via phpinfo() that ssh2 is installed?
Quick Google search seems to indicate it is not by default
PHP Install SSH2 on Windows machine
I just started learning PHP and MySQL, and I got stuck when trying to connect to my database from a PHP block. I have installed XAMPP and SQL Server Express 2012 on my machine. My server name is RAFAL-MAC and I selected 'Windows Authentication.'
I have a simple HTML page with PHP code in a file called search.php
the PHP code is
<?php
$con = mysql_connect('RAFAL-MAC','RAFAL-MAC\Rafal','');
if (!$con)
{
die( 'Could not connect: ' . mysql_error() ) ;
}
mysql_select_db("one", $con) or die(mysql_error());
?>
When I go to localhost:8080/search.php I get the following warning:
Warning: mysql_connect(): Host 'xxx.xxx.xxx.xxx' is not allowed to connect to this MySQL server in C:\xampp\htdocs\search_submit.php on line 11
Could not connect: Host 'xxx.xxx.xxx.xxx' is not allowed to connect to this MySQL server
I tried searching similar problems online, but all of the threads are about remote connections. I am just trying to connect to my local SQL server.
Any hints? I apologize for any missing information. Thanks! :)
EDIT:
I changed the server name to 'localhost'
Now I am getting this:
Access denied for user ''#'localhost' to database 'one'
Since you'd like to connect to SQL Server Express 2012, all functions beginning with mysql* will fail - since these functions speak to MySQL servers.
Please install Microsoft's MS SQL Server driver pack found here. From this page:
Perform the following steps to download and install the Microsoft
Drivers for PHP for SQL Server:
Download SQLSRV30.EXE to a temporary directory
Run SQLSRV30.EXE
When prompted, enter the path to the PHP extensions directory
After extracting the files, read the Installation section of the SQLSRV30_Readme.htm file for next steps
People in Microsoft's PHP driver forum should easily be able to answer your question, in case you still have problems after the installation of the driver.
Additionally, if connecting to the local machine, try to use these addresses:
localhost
127.0.0.1
These two addresses always reference the local machine.
I'm trying to connect to my local SQL Server 2008 R2 (have also tried it with 2005, same result exactly) with PHP. I'm using PHP 5.1 which still supports php_mssql and mssql_connect().
for some reason PHP just won't find my server, I can connect via ODBC flawlessly an that's fine, but I would like to connect to SQL Server directly.
I have connected PHP to SQL Server a million times on different servers, this one seems to be the only one giving me issue.
This is my little test code to try and get the connection working.
//define connection garbage
$db['hostname'] = "USER90C6\SQLEXPRESS";
$db['username'] = "user";
$db['password'] = "password";
$db['database'] = "kal_auth";
//connection string
$conn = mssql_connect($db['hostname'], $db['username'], $db['password']);
//does it work? :o
if($conn)
{
echo "works";
}
else
{
echo "fails";
}
The error this code produces:
Warning: mssql_connect() [function.mssql-connect]: Unable to connect to server: USER90C6\SQLEXPRESS in C:\xampp\htdocs\test.php on line 9
fails
Is there something seriously wrong with my setup? or am I missing something.
Did you enable TCP/IP on the server's configuration tool?
Is the firewall blocking any ports you might be using?
Are your MDAC (microsoft data access components) updated?
turn on mssql.secure_connection in php.ini
I think you don't miss anything.. Your connection string seems to be right (you receive a "Unable to connect" error..).
In my opinion, you problem can be a version incompatibility or a user privileges mistake. First of all: look at DLL driver you are using in PHP and check it's compatibility with you MSSQL version.
Maybe can be a good idea a fresh PHP install, with the latest stable release, if it is possible. Give a look at: http://www.php.net/manual/en/mssql.requirements.php
Good luck.