I am using WampServer Version 2.2, php5.4.3 , Apeache2.2.22 I could not use mssql_connect(), "mssql_connect() Fatal error: Call to undefined function mssql_connect()" I went through googling but still not found solution.
It is always better to use PDO which supports ms sqlserver and other databases, you can use the syntax
$dbh = new PDO('mysql:host=localhost;dbname=test', $user, $pass);
or you can refer the documentation https://secure.php.net/manual/en/pdo.connections.php
You don't have the MS SQL Drivers installed. You can check this with phpinfo();
On Linux you need mssql.so or sybase.so With debian its apt-get install php5-sybase
For windows take a look here
Drivers need to be configured for PHP to find the function
mssql_...
You could also look at PDO DB classes as they can connect to any DBS, you need the drivers installed tho.
Related
I got this problem when I run php code to connect with database in mysql.. Can anybody help me? I'm stuck.
Error:
fatal error call to undefined function mysql_connect() in php
Php code:
?php
mysql_connect("localhost","root","") or die("Could not connect to database");
mysql_select_db("dadadsdb") or die("Could not select database");
?>
mysql_* functions are deprecated in newer PHP versions and in PHP 7 they are just gone. If you are using PHP 5.x you could install these modules by sudo apt-get install php-mysql (sometimes it is sudo apt-get install php5-mysql but I recommend you to use mysqli or PDO.
Use mysqli instead of mysql.
$con = mysqli_query("host","username","password","database");
Mysql has been deprecated in PHP 5.5 for various reason and it can be replaced with MySQLi OOP(Object Oriented Programming) or the normal procedural style.
You can also use PDO that is more secure than MySQL.
I am running a Linux server that already has freetds installed, but is not configured to support dblib. Only sqlite and mysql are currently supported for PDO. MSSQL support is also enabled.
If I want to add support for dblib and enable the PDO Driver for FreeTDS/Sybase DB-lib, do I just need to run this command on the existing install:
./configure --with-pdo-dblib
If so, from which directory would I run the command?
Environment:
PHP Version 5.5.38
CENTOS 6.9
Thank you
If you have configured FreeTDS correctly, you should be able to connect like so:
$pdo = new PDO("dblib:host=mssql;dbname=$dbname", "$dbuser","$dbpwd");
If you can't, this answer gives more explicit instructions: Connect PHP to MSSQL via PDO ODBC
pdo_dblib is typically installed in most Linux distros when you install php-mssql (on CentOS and Ubuntu, for example). If the connect command isn't working, please rewrite your question to include the specific steps you have taken and the error output. Good luck!
Since writing this question, the support team at the company that is hosting this server installed the driver. I don't know exactly what steps they took to do it so I can not post a step by step answer as I would like. Closing this question.
http://php.net/manual/en/function.sybase-connect.php is removed as from PHP7.
So now I am gettings this error:
PHP Fatal error: Uncaught Error: Call to undefined function sybase_connect()
How am I supposed to connect to sybase now with PHP7?
You are using Ubuntu 16.04, so after installation of php7.0-sybase package in your system, you are able to connect with Sybase database using pdo_dblib
Example #1 PDO_DBLIB DSN examples
sybase:host=localhost;dbname=testdb
Following general PDO reference, you create connection like this
$databaseHandler = new PDO('sybase:host=localhost;dbname=testdb', $user, $pass);
My setup was working on Windows but I recently switched to Ubuntu 12.04 LTS and now it won't connect. When I load a page where I need to talk to SQL Server, I get this error:
Database driver Cake\Database\Driver\Sqlserver cannot be used due to a
missing PHP extension or unmet dependency
It is obvious that CakePHP can't find the SQL Server PDO driver.
I found many old tutorials to help me but I took the most recent (I want absolutely to be able to use PDO with my CakePHP website). This is the tutorial I followed.
Using the terminal, I can access the database with this command
sqlcmd -S my.sql.server.com -U username
What do I need to do to connect to this sql server database from my ubuntu install with CakePHP 3.x?
Update (October 17th 2016):
Microsoft recently released a preview version (on their msphpsql repo) of pdo_sqlsrv and sqlsrv for Linux. It worked successfully for me on a Ubuntu 16.04.1 LTS (Xenial Xerus) virtual machine running php7.
Original answer:
As #AD7six said:
CakePHP's sql server driver is for using PDO_SQLSRV; If you need to use ODBC, there isn't one in the core.
PDO_SQLSRV is working if you are on Windows. CakePHP has a driver that support it natively.
If you want to talk to a SQL Server Database from Linux, you have to use the ODBC driver. You can install the driver using this tutorial which helped me a lot. After that, you will be able to connect to your database using PDO (not CakePHP):
try {
$query = new PDO(
"odbc:Driver={SQL Server};Database=[Database name]; Server=[Hosame]",
"[Username]",
"[Password]");
} catch (PDOException $e) {
echo 'Connection failed: ' . $e->getMessage();
}
Thanks everybody for your help. It could be great to find/code a CakePHP 3 database driver for odbc.
The new version of CakePHP supports PDO-sqlsrv which is new the MS driver that supports PHP 7 and higher.
http://php.net/manual/en/ref.pdo-sqlsrv.php
It also allows you to connect to Azure. Example:
//Establishes the connection
$conn = new PDO( "sqlsrv:server=$serverName ; Database = $database", $uid, $pwd);
Am using windows 8 pro, Wamp server (php V5.3.5, apache V2.2.17), Sql server 2005 express editon. I have downloaded the sqlsrv drivers and extracted them into the php extention folder (C:\wamp\bin\php\php5.3.5\ext), have also update the php.ini file by adding the extentions
extension=php_sqlsrv_53_ts_vc6.dll
extension=php_pdo_sqlsrv_53_ts_vc6.dll
I used this two after series of try and error on all the dll file, it was this two that come up with no error, when restarting the wamp server
This is the connection line of code;
$con = sqlsrv_connect('TAQUATECH\SQLEXPRESS') or die("cannot connect");
It came up with the following error;
Fatal error: Call to undefined function sqlsrv_connect() in
C:\wamp\www\Webs\client.php on line 7
pls, i need somebody to help me on this, i will really appreciate
Sorry if too late to answer, but I had the same error, and I found out that Wamp Server 64bit does not support SQL Server Connection, you must install a 32bit version of wamp server.
For those using 64-bit systems (OS, WAMP, MSSQL), these 64-bit drivers can serve them and fix the error:
Fatal error: Call to undefined function sqlsrv_connect() in C:\wamp\www...
Drivers SQLSRV x64:
http://robsphp.blogspot.in/2012/06/unofficial-microsoft-sql-server-driver.html
You'll need to install and enable sqlsrv on your web server. Have a look at the installation page on the official PHP website.
Installation of Microsoft Drivers 3.0 for PHP for SQL Server will fix this issue. Also try this PHP Manual.
EDIT :
The most recent version of the driver is available for download here:
» SQLSRV 3.0 download. If you need support for PHP 5.2 and/or PHP
compiled with VC6, use the 2.0 release of the driver: » SQLSRV 2.0
download.
Source
Yap, I have gotten a work-around;
The problem was, running the php script using apache server on my system, I stoped the wamp server and configure fastCGI for PHP using IIS 7, You can get a video tutorial Here
http://www.iis.net/learn/application-frameworks/running-php-applications-on-iis/set-up-fastcgi-for-php.
It simple and nice, now i can connect to both sql server 2005 and 2008
My PHP Details
Version => 5.3.5
Compiler => MSVC6 (Visual C++ 6.0)
SqlSrv Driver => php_sqlsrv_53_ts_vc6.dll
use 32 bit PHP Version.
enable below one of them in php.ini
[PHP_PDO_SQLSRV_53_NTS]
extension=php_pdo_sqlsrv_53_nts.dll
[PHP_SQLSRV_54_NTS]
extension=php_sqlsrv_54_nts.dll
[PHP_SQLSRV_53_NTS]
extension=php_sqlsrv_53_nts.dll
[PHP_PDO_SQLSRV_54_NTS]
extension=php_pdo_sqlsrv_54_nts.dll
thease dll version you can downlowd online