I have installed the lastest version of sql-server for php. I use a simple USBWebserver and I have pasted all the driver files to the map C:\php\ext (see image below). In the file php\php.ini, I have place this string behind:
extension=php_sqlsrv_56_ts.dll
Here can you see all the files in C:\php\ext for running the driver:
Whit this I have no errors (but maybe he didn't throw it).
Now my problem is when I make my connection to the sql server database. I have the following error:
Fatal error: Call to undefined function sqlsrv_connect() in c:\root\add.php on line 2
This is my code where I've the exception:
$conn = sqlsrv_connect( array("Database"=>"Immo"), ".\\SQLEXPRESS");
Can anyone help me?Thanks and sorry for my poor english.
The string that you must place in your php\php.ini file is this:
extension=php_sqlsrv_54_ts.dll
And for make a connection you must turn the two arguments from place.
$conn = sqlsrv_connect(".\\SQLEXPRESS", array("Database"=>"Immo"));
This has help me to make a connection to a SQL-server with php.
Related
I've been tasked with taking all of our MySQL databases and migrating them to SQL Server. In attempting to get PHP 5.3.24 to work with MSSQL, I've done the following:
Copied the non thread-safe drivers to /php/ext.
Updated my php.ini file to include the following two lines:
extension=php_pdo_sqlsrv_53_nts_vc9.dll;
extension=php_sqlsrv_53_nts_vc9.dll
Restarted IIS 7 running on Windows Server 2008 R2.
phpinfo shows sqlsrv under Registered PHP Streams, and sqlsrv also appears under PDO drivers and pdo_sqlsrv support shows as "enabled." Yet, when I try to connect via my application, I get the following:
Fatal error: Uncaught exception 'PDOException' with message 'could not find driver' in C:\inetpub\wwwroot\mystuff\myphpconnectfile.php
My connect string looks like this:
$con = new PDO("mssql:host=xxx.xxx.xxx.xxx,1433;dbname=mydb", "user", "pwd");
$con -> setAttribute(PDO::ATTR_ERRMODE, PDO::ERRMODE_EXCEPTION);
return($con);
Looks like it's finding the server okay, but not the PHP/PDO mssql drivers. What have I missed?
EDIT: Configure Command under phpinfo shows the lines "--without-mssql" "--without-pdo-mssql". I don't know where to go to change this, or if it's necessary.
You're using an invalid DSN connection string for MSSQL. You need to use the format found here.
new PDO('sqlsrv:Server=xxx.xxx.xxx.xxx,1433;Database=mydb', 'user', 'pwd');
I'm trying to connect to an MSSQL database with PHP and encounter a very frustrating error while trying to connect. It loads for a minute, before printing out the following message:
Fatal error: Uncaught exception 'PDOException' with message 'SQLSTATE[08001]:
[Microsoft][SQL Server Native Client 11.0]Named Pipes Provider: Could not open a connection to SQL Server [53].
Here's my connection string:
DB::config("sqlsrv:Server={$dbHost} ; Database={$dbName}", $dbUser, $dbPass);
And in my DB class:
public static function config($dsn, $user, $pass)
{
self::$_pdo = #new PDO($dsn, $user, $pass);
...// intentionally left out
I'm very baffled. I have the following module configured in my php.ini file: extension=php_pdo_sqlsrv_54_ts.dll. Although I think I installed it right and I don't receive any error message about the driver not working, this bit of PHP prints nothing:
if (function_exists( 'sqlsrv_connect' ))
echo "hey";
and as you can see from my error message above SQL Server Native Client 11 appears to be working. I'm on a Windows platform. I tried disabling the firewall to no avail. I don't have much information about the SQL server or I would share it here.
This is my first time posting on Stack, so I apologize if I'm leaving out a key piece of information or I'm not following proper etiquette in some way, but any help is definitely appreciated.
Also, I should add that I've already done too much Googling, and haven't had any success.
My install process actually worked, but the connection was indeed invalid. I should have been using the IP address as the host name, which I was not. I was also using a colon instead of a comma before the port number. Finally, no spaces can be allowed in the connection string, which I thought would be automatically stripped out. So, here's a valid connection string for those of you that may find yourself in a similar predicament:
$connectionString="sqlsrv:Server=123.123.12.1,9864;Database=mssqldatabaseWootWoot";
Also, in response to my earlier observation about that function sqlsrv_connect, I had not enabled the driver necessary for that function. It is located in php_sqlsrv_54_ts.dll, which after enabling, reported the function as existing.
Thanks to anyone who put any time into solving this.
I ran into the same problem but I found that I did not need to use the IP address, the server name worked just fime. Also I was not sure what port my server was using, I found the information here: How to find the port for MS SQL Server 2008?
I also found the following links helpful in getting PDO to work:
PHP PDO Connection to SQL Server with integrated security?
Use of PDO in classes
MS SQL Server (PDO) — Microsoft SQL Server Functions (PDO_SQLSRV)
I know ncksllvn solved his problem so I hope this helps whoever else visits!
This question already has answers here:
Closed 10 years ago.
Possible Duplicate:
PHP Fatal error: Call to undefined function mssql_connect()
I am developing a light-weight PHP application which accesses a remote SQL server db.
So far, I am out of luck in getting connection setup to SQL Server db through my PHP script.
I keep getting this error when I am trying to connect to sql DB:
Fatal error: Call to undefined function mssql_connect()
I get similar error when I try sqlsrv_connect($myServer, $myUser, $myPass) too
Here is what I have already tried:
I search for solution on web for hours, but nothing works.
I downloaded drivers from http://www.microsoft.com/en-us/download/details.aspx?id=20098
and unzipped them into php/ext folder
modified php.ini to add newly downloaded drivers lines:
extension=php_sqlsrv_54_ts.dll
extension=php_pdo_sqlsrv_54_ts.dll
[sqlsrv]
sqlsrv.LogSubsystems = 1
sqlsrv.LogSeverity = 1
sqlsrv.WarningReturnAsErrors = 0
Restarted the Apache server
But, see phpinfo() output it doesn't have sqlserv in it http://bit.ly/TkMC6V
Just so you know, I am developing this on my windows machine by installing EasyPHP. This website will be deployed on a Unix box. I tried to connect sql server through php on both Windows and Unix machine without any success.
Version info:
SQL Server 9.0.5000
PHP ver 5.4.6
Apache 2.4
I just dont get sqlsrv in my phpinfo() as mentioned in this question PHP Fatal error: Call to undefined function mssql_connect()
Is there a different way to install the drivers, other than what I have outlined above?
Let me know if you need more info.
Thanks!
I found the issue, by looking at phpInfo() output carefully
Loaded Configuration File C:\Program Files (x86)\EasyPHP-12.1\apache\php.ini
I was modifying php.ini in php directory.
But, I needed to modify the one in apache directory
I can delete this silly question.
But, I think it might be helpful for someone facing similar issue.
Jeez , I spent 4 hour on this stupid issue. :)
I have been trying to connect to a ibm db2 database but it seems impposible. The as400 is in a different server than the one running php.
Everytime I do a db2_connect I get the following error:
Fatal error: Call to undefined function db2_connect()
How can I make this function work?
Tip: I've already tried with odbc and it was a lost of time, but I'm open to suggestions on that path as well.
[EDIT]
I finally changed to java... it was impossible with php...
Check your php.ini file and make sure it has the DB2 extension enabled. http://www.php.net/manual/en/install.pecl.php
Try this link:
http://www.theregister.co.uk/2006/08/09/db2_udb_part2/
Deals with:
Installing the PHP DB2 extension,
Creating a connection,
Obtaining a result set
Also gives as an alternative the PDO option.
But as for DB2 on the AS400, am not sure if something still needs to be installed on the
AS400 for this to work?
Anyway, have used the ODBC Client Access with no problems at all. What difficulty did you run into?
May is ask you about how to connect to Microsoft SQL server 2005 enterprise using PHP.
I am using Appserv 2.5.10 ( Apache 2.2.8, PHP 5.2.6) and SQL server 2005
After I place the extension download from this link :
http://www.microsoft.com/en-us/download/details.aspx?id=20098
enable the php.ini file by adding these lines.
extension=php_pdo.dll
extension=php_sqlsrv_52_ts_vc6.dll
extension=php_pdo_sqlsrv_52_ts_vc6.dll
Restart Apache using this code to connect
$link = mssql_connect($server, $user, $pass);
Error shown in browser is
Fatal error: Call to undefined function mssql_connect() in G:\AppServ\www\testmssql_connect.php on line 12
can anyone help me ?
NOTE: i am using windows server 2003 and i don't found this OS in OS supporting list of Microsoft Driver 3.0 for PHP. Is this issue cause the problem ?
Look at this link:
PHP Fatal error: Call to undefined function mssql_connect()
1) Check your PHP.INI file's extension_dir
2) Make sure you copied your .dlls into that directory (for example, into C:\PHP\ext").
3) Create a dummy page to call phpinfo();. Display the page in a browser. Make sure you see entries for "sqlsrv".
'Hope that helps!