Page 1 of 1

Connect to MySQL on WIMP in Visual Studio 2017

PostPosted: June 30th, 2018, 2:16 am
by noCodeMonkey
I am using the same connection information that I use in another PHP editor with no problem. However in VS with DevSense PHP I can not make a connection.

When debugging the app hangs at:
$mysqli = new mysqli("localhost", "root", "password","dbName", port<int>, null);

I hope you will not come back with a reply that says connecting to php is outside your support scope. Using PHP without database support is useless.

Re: Connect to MySQL on WIMP in Visual Studio 2017

PostPosted: June 30th, 2018, 9:18 am
by Jakub Misek
Does it hang with an error or a warning?

When using "mysqli" you have to have enabled "mysqli" PHP extension in "php.ini" configuration file.

To locate the file, open project properties and navigate to Server tab. There is an actual path to the configuration file. Uncomment or add line
Code: Select all
extension=php_mysqli.dll

Re: Connect to MySQL on WIMP in Visual Studio 2017

PostPosted: July 4th, 2018, 7:33 pm
by noCodeMonkey
I am posting this reply for others who may be setting up the same environment. The errors I was experiencing had nothing to do with connecting to MySql. It turned out that PHP7.2 has a number of changes from v7.1 that broke a lot of code.

Visual Studio 2017 with DevSense makes it relatively straight forward to debug the code. In fact it makes it super easy to switch back and forth between different versions of PHP.
Image

You can also run different servers if desired. You can run the built in server with the settings below.
Image

You can also run the IIS server that comes with the Ultimate versions of Windows, with the following settings. Make sure to add the port number that Visual Studio generates for you (not 12345 as shown).
Image

Connecting to MySql is also straight forward. My mistake was in including the port number in the connection string. Even though VS runs on a specific port, do not include the port in the connection string.

As per php.net the proper connection string is:
$link = mysqli_connect("127.0.0.1", "my_user", "my_password", "my_db");

I found that the default settings were all fine but if there are problems check the following.
The php.ini file should point to the correct extensions directory which must contain:
extension=php_mysqli.dll

Congratulations to DevSense for making a terrific, bug-free PHP add-on for Visual Studio.