0

I am new to php. I am trying to connect to SQLEXPRESS server using mysqli from php script. Here is my code:

<?php
$servername = "localhost";

// Create connection
$conn = new mysqli($servername,"root","");

// Check connection
if ($conn->connect_error) {
    die("Connection failed: " . $conn->connect_error);
    } 
echo "Connected successfully";

?>

I get an error that the target machine actively refuses the connection. My server is listening connections on port 63083. When I enter the port number in $servername:

 $servername = "localhost:63083";

then the script does not respond and after a few minutes I get an error that MySQL server has gone away. I would really appreciate some help in this regard.

Thanks

4
  • Where is the database server located? Is it on your computer? Commented Mar 19, 2015 at 17:43
  • try $conn = new mysqli($servername,"root"); Commented Mar 19, 2015 at 17:44
  • 2
    I could be wrong but I think SQLEXPRESS is MSSQL not MySQL. I think you'll need this extension to work with the DB. Commented Mar 19, 2015 at 17:44
  • I think War10ck is correct, but also looking at the link below it looks like if you want to set the port in mysqli you need to use the port parameter to the connect method: php.net/manual/en/mysqli.construct.php Commented Mar 19, 2015 at 17:48

1 Answer 1

2

You cannot connect to an SQLEXPRESS server using PHP's mysqli. SQLEXPRESS has its own method of connecting with PHP. mysqli is only for MySQL servers.

Reference: http://www.sitepoint.com/sql-server-php/

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.