In php, to connect to MSSQL server , what is diffrence between odb_connect() and mssql_connect()???
odbc_connect is a generic database connection (you can specify the driver), while mssql_connect is MSSQL specific
Also the manual says that complex queries may fail with odbc drivers.
odbc_connect() requires you have the PHP ODBC extension loaded and UNIXodbc installed and configured on the web server, whereas mssql_connect() only requires that you have the MSSQL extension.
If your looking to connect to a SQL Server via PHP, might I recommend that you use Microsoft's SQLSRV PHP driver. It's much better than the native php_mssql extension and gives you a lot more functionality. Make sure you also install SQL Server native client, or it won't work.
Related
I am trying to connect MSSQL server database on different server using PHP (5.4.45). I already know about sqlsrv_connect() and odbc_connect() and tried them. But we cannot use them without installing their extensions and enabling them in php.ini file. I wonder is there any way to establish connection with MSSQL server without installing/enabling any extension. As i do not have PHP server access and client has refused to provide the same.
Any one can help?
nope. not possible without installing an extension.
I installed XAMPP on Windows Server 2008. Apache is running with PHP 7.0.13. I modified php.ini file for to enable ODBC driver, like this:
extension=php_pdo_odbc.dll
Even, I see ODBC in PDO drivers section when I use phpinfo(). But, I get an error when I use odbc_connect.
How fix this? Please, help me. Thanks.
PHP offers two kinds of support for ODBC (and most database drivers):
Through PDO
Standalone
You have enabled the PDO version (php_pdo_odbc.dll), but you're trying to use a non-PDO function. You've got two options:
Enable the standalone functionality via php_odbc.dll (note the slightly different name)
Use ODBC via the PDO interface
PDO is
a lightweight, consistent interface for accessing databases in PHP
and I generally prefer it to the database-specific interfaces, but either should work.
I'm running a WAMP stack and and trying to connect to an SQL Server instance with PHP's PDO.
I've downloaded the PHP drivers for MS SQL from here and added **php_pdo_sqlsrv_54_ts.dll** into PHP's extension folder.
Then added "php_pdo_sqlsrv_54_ts.dll" to the list of extensions in php.ini.
I know I'm using the correct driver because I'm using PHP version 5.4.3 and **phpinfo()** reports that it's thread-safe.
However, after restarting Apache **phpinfo()** (and **PDO::getAvailableDrivers()**) both report that only the mysql, odbc and sqlite PDO drivers are loaded.
This means that when I attempt to connect to my SQL Server instance I get the error:
could not find driver
Can anyone advise on how to get this working?
Sounds like the SQL Native Client is missing.
System Requirements
Microsoft SQL Server 2012 Native Client available in the SQL Server 2012 Feature Pack.
I have installed Apache2.2 and then installed PHP5.4.8. I cannot get my new .php file to load in a browser because it keeps giving me the error Fatal error: Call to undefined function mysql_connect(). When I load the test.php file which has only this in it:
<?php phpinfo(); ?> it returns a page that shows information about PHP but where it would show the MySQL modules it only shows mysqlnd. What is that? Also, I have gone through the php.ini file and uncommented the proper lines for MySQL integration as well as having edited the Apache2.2 httpd file. Does anyone have any answers as to why MySQL isn't working? Thanks in advance.
Also, Ive tried many of the solutions from this website as well as many google searches. I can't seem to figure it out. :-(
1) Have a look on choosing MySQL API. It is recommended to use mysqli extension.
2) According to Other changes to extensions, the MySQL extensions mysql, mysqli and PDO_mysql use mysqlnd as the default library now.
A quote from MySQL Native Driver - mysqlnd site:
Although MySQL Native Driver is written as a PHP extension, it is important to note that it does not provide a new API to the PHP programmer. The programmer APIs for MySQL database connectivity are provided by the MySQL extension, mysqli and PDO MYSQL. These extensions can now use the services of MySQL Native Driver to communicate with the MySQL Server. Therefore, you should not think of MySQL Native Driver as an API.
That means, the mysqlnd extension does not export any function you can use in your scripts, but acts as a bridge between your code and one of mysql, mysqli, pdo_mysql extensions.
You mentioned, that phpinfo() shows only mysqlnd. The fact you don't see section titled MySQL there means that mysql extension is not enabled (commented out) in php.ini (Windows) or your php is not compiled with mysql support (Linux). More details about installing MySQL extension are here.
What is your OS?
To have a successfull MySQL connection you should:
Install the MySQL Server
Configure the PHP to use the proper mysql socket: (in php.ini search for mysql.default_socket - point it to the mysql server).
Reboot the web server - Apache
We need to access a Teradata database via php application We don't have odbc (unixodbc etc) on the server.
How might one go about connecting to a teradata database quickly.
Keep in mind - this app needs to be as portable as possible.
Teradata provides an ODBC driver. Once installed, it can be accessed via the unixODBC driver manager, assuming your php was built with "--with-unixODBC=shared,/usr".
PHP can then connect to a Teradata database with odbc_connect($dsn, $user, $passwd);
The Teradata ODBC driver installation includes a sample odbc.ini file, which you can cp to .odbc.ini in your home directory, then modify to contain the DSN for your Teradata database.
Set the environment variable ODBCINI to the location of your odbc.ini file to use (/home/johndoe/.odbc.ini is common).
Be warned: the Teradata ODBC driver provides a rich set of DML statements, but very few are exposed through the unixODBC driver manager. The collection of PHP's odbc_xxxx() functions is a crippled subset of what the Teradata ODBC driver offers.
This method would help you if u are ok with the memory implications and this would help you if you have teradata command line utility BTEQ installed on your machine.
But better method would be by ODBC as it gives you the flexibility. In the above method of command line execution of SQL scripts by system() function, you can use an easier language like R for parsing the output resultset.
I think you may also do it by jdbc connection. You can also download any of these odbc/jdbc drivers from this link.
You may be out of luck.
PDO doesn't have a native driver
ADODb doesn't have a native driver
judging from what I find from a cursory web search, I'd say it is not possible to connect from PHP to a Teradata database without ODBC.