Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
995 views
in Technique[技术] by (71.8m points)

php - Fatal error: Call to undefined function sqlsrv_connect() in C:xampphtdocs

I am using

  • Xampp version 3.2.1 with PHP version 5.6.8.
  • Microsoft Azure SQL server

GOAL

I am trying to create a web app that will access to my database, and be able to SELECT, INSERT, UPDATE and DELETE records.


PROBLEM

I cannot connect to the database server


ERROR

Fatal error: Call to undefined function sqlsrv_connect() in C:xampphtdocsBLTEmployee_Database .php on line 25


CODE

<html>
<head>
    <Title>Employee Database</Title>
</head>
<body>
<form method="post" action="?action=add" enctype="multipart/form-data">
    Last name <input type="text" name="LastName" id="LastName"/></br>
    First name <input type="text" name="FirstName" id="FirstNamne"/></br>
    E-mail address <input type="text" name="Email" id="Email"/></br>
    User Id <input type="text" name="UserId" id="UserId"/></br>
    Password <input type="password" name="Password" id="Password"/></br>
    <input type="submit" name="submit" value="Submit"/>
</form>

<?php
$serverName = "jy4nij6vuy.database.windows.net,1433";
$connectionOptions = array("Database" => "robertfarb",
    "UID" => "robertFarb",
    "PWD" => "******");
$conn = sqlsrv_connect($serverName, $connectionOptions);

if ($conn === false) {
    die(print_r(sqlsrv_errors(), true));
}
?>

</body>
</html>

THIS IS WHAT I TRIED SO FAR

  • I have installed the Microsoft PHP for SQL drivers and followed all the instructions to load the driver, but it does not seem to be working!
  • I added the php_sqlsrv_56.ts.dll file to the extensions folder of PHP, and also the php_pdo_sqlsrv_56.ts.dll.
  • I also added the extension=php_sqlsrv_56.ts.dll line to the php.ini file.

Any help would be much appreciated!

See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Reply

0 votes
by (71.8m points)

The MSSQL extension is not available anymore on Windows with?PHP 5.3 or later. SQLSRV, an alternative driver for MS SQL is available from Microsoft: ? http://www.microsoft.com/en-us/download/details.aspx?id=20098

Step by Step

  1. Download SQLSRV32.EXE (Microsoft Drivers for PHP for SQL Server) from: http://www.microsoft.com/en-us/download/details.aspx?id=20098

  2. Choose path: C:xamppphpext

enter image description here

  1. Uncomment or Append extension = php_sqlsrv_56_ts.dll in php.ini

  2. Restart Apache from XAMPP Control Panel (Stop/Start)

I tested it and it works 100%

You can find the most recent compiled binaries in the official Microsoft Git repository.


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
OGeek|极客中国-欢迎来到极客的世界,一个免费开放的程序员编程交流平台!开放,进步,分享!让技术改变生活,让极客改变未来! Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...