Welcome to the Treehouse Community
Want to collaborate on code errors? Have bugs you need feedback on? Looking for an extra set of eyes on your latest project? Get support with fellow developers, designers, and programmers of all backgrounds and skill levels here with the Treehouse Community! While you're at it, check out some resources Treehouse students have shared here.
Looking to learn something new?
Treehouse offers a seven day free trial for new students. Get access to thousands of hours of content and join thousands of Treehouse students and alumni in the community today.
Start your free trial
Ryan Smee
3,392 PointsConnecting PHP, MS SQL Server & Mac
I have started working on a project with a friend. Working locally on my Macbook I have created a simple web app using front end languages, and php to connect to a local MySQL db using MAMP.
My friend who is a back end guy and a PC User, has been building a more complex backend with stored procedures etc.
The issue we have is he uses MSSQL and so I am having trouble making my end communicate with his. He has uploaded hiss MS SQL database to an Amazon AWS hosting area and its all working fine. I can view it using RQLSQL etc but can't seem to connect to it using PHP in my project?
Does anyone know of a way I can work locally on my Mac and connect to this db??
Ryan Smee
3,392 PointsYeah i was starting to think that too. Thank you for having a look though.
3 Answers
Ryan Smee
3,392 PointsFor anyone who has the same issue. I ended up using the 'FreeTDS' plugin, installed using Homebrew via the command line. I then added 'brew install -v php56 --with-apache --with-mssql --without-snmp' to the terminal to reinstall php5.6.2 with the new drivers. The reason I have to do it with '--without-snmp' was because I have upgraded to Yosemite and that part of the driver doesn't work correctly as of yet. Its now working perfectly :)
I then just use simple MSSQL commands as found on the PHP website:
$dbUser = 'username';
$dbPass = 'password';
$dbServer = 'url';
$link = mssql_connect($dbServer, $dbUser, $dbPass);
if(!$link) {
echo'Could not connect';
die('Could not connect: ' . mssql_error());
}
echo"Successful connection \n";
mssql_select_db('dababaseName', $link);
I hope this helps anyone.
Nikolay Batrakov
9,604 PointsShouldn't be a problem.
You need to setup an SQL server on your AWS machine
You need to grant access to a database for remote user. Do like
> mysql -u root -p
mysql> GRANT ALL ON yourdatabase.* TO user@% IDENTIFIED BY 'password';
Then you shall be able to connect to your database from PHP like
mysql_connect("$dbhost", "$dbuser", "$dbpass")
Check if you set a rule on your AWS machine which allows your SQL server to enable incoming connection to the port set up while install the server (3306?)
% is a wildcard gives the user ability to connect to database from any host.
check this also
hope it helps
Ryan Smee
3,392 PointsI believe the SQL Server instance is set to allow all incoming traffic at the moment as we got a load of security popups when I did it. Also it appears you are referencing MySQL where as we are using MS SQL Server which is the bit thats making it hard :/
I'm not sure if I just need to look into freeTSD or something?
Nikolay Batrakov
9,604 PointsMy mistake, I should be careful while reading, sorry about that. Ya, MS SQL makes the problem bit harder. I did this with MySQL lot of times and have never done it before with MS SQL. I'll ask some of my friends, maybe we can figure out something.
Ryan Smee
3,392 PointsNo worries. Yeah My Sql makes life a lot easier and it's what I am used to using. But my friend is well versed in MS SQL so understandably doesn't want to make the tradition and I don't really fancy taking up .net haha
If you do hear anything from your friends, that would be fantastic. cheers
Christian Andersson
8,712 PointsChristian Andersson
8,712 PointsThis is quite a complex and very specific question you're asking. I think you're better off asking the peeps over at http://stackoverflow.com. Good luck.