Guest Report post Posted October 23, 2016 Hello there, I've started studying php and sometime ago I tried to establish SQL server connection however encountered an error: php_network_getaddresses: gethostbyname failed. errno=2 A couple of things to consider: - SQL works fine. - I can connect to the SQL using the username & password given below. PHP code: <?php $servername = ".\SQLExpress"; $username = "sa"; $password = "Y87dc#$98"; $dbname = "AccountServer"; $conn = new mysqli($servername, $username, $password); if ($conn->connect_error) { die("Connection failed: " . $conn->connect_error); } ?> Any help is appreciated! Share this post Link to post Share on other sites
Wrexor 61 Report post Posted October 23, 2016 You cannot use mysqli extension to connect to a MSSQL server. Mysqli is used for connecting to mysql server. For mssql you have to you mssql or sqlsrv extension. Share this post Link to post Share on other sites
Guest Report post Posted October 23, 2016 13 minutes ago, Wrexor said: You cannot use mysqli extension to connect to a MSSQL server. Mysqli is used for connecting to mysql server. For mssql you have to you mssql or sqlsrv extension. Thanks for a quick response. I edited the code and have the same error. <?php $servername = ".\SQLExpress"; $username = "sa"; $password = "Y87dc#$98"; $dbname = "AccountServer"; mysql_connect($servername, $username, $password) or die('Could not connect: ' . mysql_error()); ?> Share this post Link to post Share on other sites
V3ct0r 2,117 Report post Posted October 23, 2016 @qwerty Use mssql_connect() and mssql_get_last_message() instead of mysql_connect() and mysql_error() Some useful links / Полезные ссылки Tips for making a topic in 'Questions & Help' / Рекомендации по созданию тем в разделе "Помощь" Server Advertising Section Rules / Правила раздела "Реклама серверов" Available e-mail domains for registration / Допустимые e-mail домены для регистрации User groups / Группы пользователей User ranks / Звания пользователей "Broken" pictures on the forum / "Битые" изображения на форуме Beware of scammers! / Осторожно, мошенники! My developments / Мои разработки Mods for client and server / Моды для клиента и сервера PKOdev.NET website for Tales of Pirates Server / PKOdev.NET веб-обвязка для сервера Пиратии I do not provide any help in private messages and outside the forum. Use 'Questions & Help' section please. Thank you for understanding! Я не оказываю какую-либо помощь в личных сообщениях и вне форума. Пожалуйста, используйте раздел "Пиратия: Помощь". Благодарю за понимание! Share this post Link to post Share on other sites
Perseus 98 Report post Posted October 23, 2016 (edited) Nice to see someone learning something :D. You're still using mysql Mysql != mssql You're gonna have to learn sqlsrv ( which is the latest library for connecting php->mssql ) You could go for mssql by hacking around a little and installing the DLLs manually but I'd advise against that since its deprecated. An easier way would be to learn PDO, its an abstraction layer which makes everything that much easier. Here's what you should be using :http://php.net/manual/en/function.sqlsrv-connect.php A pdo guide if you decide to go that way : http://wiki.hashphp.org/PDO_Tutorial_for_MySQL_Developers You'll just need to replace mysql with sqlsrv in the connection line and everything else remains the same. Hit me up on Skype if you need any more help : iturble Edited October 23, 2016 by Perseus Share this post Link to post Share on other sites
Guest Report post Posted October 23, 2016 3 minutes ago, V3ct0r said: @qwerty Use mssql_connect() and mssql_get_last_message() instead of mysql_connect() and mysql_error() 2 minutes ago, Perseus said: ... @V3ct0r, @Wrexor thanks - it's working now @Perseus, yup I've just realized haha, I'll take a look on that. Thanks! In case someone comes across the same issue: <?php $servername = ".\SQLExpress"; $username = "sa"; $password = "Y87dc#$98"; $dbname = "AccountServer"; mssql_connect($servername, $username, $password) or die('Could not connect: ' . mssql_get_last_message()); ?> Share this post Link to post Share on other sites