I'm trying to connect to a Sybase database with PHP5. I believe I've successfully compiled PHP with PDO_DBLIB, as phpinfo() lists dblib under PDO drivers, and freetds as the pdo_dblib flavour.
However, when I try to test a connection, I get an error reading:
'PDOException' with message 'could not find driver'
I'm trying to connect to a server on my LAN with this code:
$dbh = new PDO("sybase:host=192.168.1.xxx;dbname=[database-name]", '[user]', '[pass]');
Any suggestions would be greatly appreciated!
You should use dblib instead of sybase, like this:
$dbh = new PDO("dblib:host=192.168.1.xxx;dbname=[database-name]", '[user]', '[pass]');
PDO wouldn't work, or at least there is no PDO Sybase support for php. On Windows, you can use ODBC, and PDO_SQLSRV or PDO_ODBC, it might sound weird, but it should work.
Second option and I would recommend it, is to connect directly to Sybase (SqlAnywhere), but you need to install SQL Anywhere PHP Module
If you are using Ubuntu you can put the LD_LIBRARY_PATH inside envvars and it seems to read... still trying to find a way to get it to stick on RHEL based systems... Windows I am not too sure about I would hope you could set a system wide variable under
my computer -> properties -> advanced options
If are using RHEL based systems it might be better to include the:
export LD_LIBRARY_PATH=/path/to/library/ in the httpd restart script (check to see if it loads /etc/sysconfig/httpd and if so add the line in there - now restart apache and you should see some activity.
Related
In PHP scripts, it looks like this is how you connect to an odbc database:
$connection = odbc_connect("Driver={SQL Server Native Client 10.0};Server=$server;Database=$database;", $user, $password);
The problem I'm having is that I don't know what to use for "Driver=". What I put in there is what was provided for another script I saw. In my script, all I do is try to connect using this line, but I get the following error:
Warning: odbc_connect(): SQL error: [unixODBC][Driver Manager]Data source name not found, and no default driver specified, SQL state IM002 in SQLConnect in /srv/www/htdocs/site/test.php on line 8
From what I can tell, it looks like the driver I specified is incorrect. The database I am trying to connect to is an MSSQL database, and I only plan to query for information from it. Is there a way to list the database drivers I have available on my system? I've never had to install/configure any drivers like this before (I've never done anything like this; all php work I've done in the past has been with MySQL). Also, I don't want to compile other software onto my system (if possible); I would prefer to install all packages from repos.
You should have a file called odbcinst.ini (probably in /etc or /usr/local/etc but you can locate it with the command odbcinst -j). This file defines your ODBC drivers. Each driver is named within the [] in each section.
You might find Linux ODBC useful as it contains a thorough explanation of unixODBC, how it works and how to define data sources.
The question was how to find the list of ODBC drivers available. In the command line run:
odbcinst -q -d
This will list the drivers if you don't know already.
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?
I have an application that I made with PHP and MSSQL2000, but now want to connect it to a MSSQL2005 database. It's always failing and after doing some research I was told to download the ntwdblib.dll and replace the old one in my PHP directory which I did, but still cannot connect to it. I also uncommented the MSSQL extensions in my php.ini file.
Please can somebody help me with this?
http://www.php.net/manual/en/mssql.installation.php
The MSSQL extension is enabled by
adding extension=php_mssql.dll to
php.ini.
To get these functions to work, you have to compile PHP with
--with-mssql[=DIR] , where DIR is the FreeTDS install prefix. And FreeTDS
should be compiled using
--enable-msdblib .
also
MS SQL functions are aliases to Sybase functions if PHP is compiled with Sybase extension and without MS SQL extension.
<Edit>
Just asking. Do you have a mssql_connect function? Or does the connect fail? If the connection fails, be sure to enable TCP/IP in MSSQL (using SQL Server Configuration Manager). And I also recalled enabling Named Pipes, but I'm not sure it's needed.
</Edit>
As an alternative you could look at COM and ADODB.
Example of COM and ADODB, connecting to SQL Server using Windows Authentication:
$this->m_conn = new COM("ADODB.Connection");
$this->m_conn->CommandTimeout=1200;
$dsn="Provider=SQLNCLI;Data Source=server_name;Integrated Security=SSPI;Initial Catalog=database_name;Application Name=YourAppName - ".$user['name'];
$this->m_conn->Open($dsn);
if(!$this->m_conn)
throw new Exception("Could not start ADO",101);
$this->m_comm = new COM("ADODB.Command");
$this->m_comm->ActiveConnection=$this->m_conn;
$this->m_comm->CommandTimeout=1200;
Then execute a command
$this->m_comm->CommandText=$sql;
$res=$this->m_comm->Execute();
Then extract the data
if(($num_cols=$res->Fields->Count())>=1)
{
$return=array();
while(!$res->EOF)
{
$row=array();
for($i=0;$i<$num_cols;$i++)
$row[$res->Fields($i)->name]=$res->Fields($i)->value;
$res->MoveNext();
$return[]=$row;
}
}
$res->Close();
return $return;
Not sure about speed on a lot of requests, but it's a good way to do it without much fuss, and using DSNs with which you can specify much more than using function parameters.
EDIT:
You can define your own mssql_connect(), mssql_command(), etc, using ADO. That's a workaround if regular mssql extension won't work.
You can also try the build in database wrapper PDO from php.
Here is some information about PDO: PDO
And here is information on the use of MSSQL with PDO MSSQL and PDO
thank you very much for your help.
Actually i did find out a way of making it work
First of all let me start with what i have compared to the system requirements
MY SYSTEM
OS:-Win xP SP2
PHP :- 5.3.5
MSSQL 2005
SQL Native client 2005
Required
Recommended :-Win xP SP3
PHP :- 5.2.4 or later
MSSQL Server 2008 Native Client (on the same computer php is running)
SQL Server Driver For PHP
after upgrading my windows to service pack 3 i then downloaded and installed the MSSQL Server 2008 Native Client
then installed the SQL Server Driver For PHP 2.0 which ask for a directory to save the dll files.
I browse to the php directory and then the 'ext' folder where it copied the dll files to.
Then went to the php.ini file and add these two lines under the Dynamic Extensions.
extension=php_sqlsrv_53_ts_vc6.dll
extension=php_pdo_sqlsrv_53_ts_vc6.dll
Then restart my webserver and booommm....i got it working..
did a test connection to the database and it was succesfull..
Hope this will help others and thank you all for your assistance really appreciate it..
Peace
I have the issue, to get a PHP script connecting to an Informix DB. I thought installing the Zend-server community edition and in addition the pdo_informix extension. When I run the Zend-server admin in the browser, I see the pdo_informix extension marked as "green". Afterwards I've installed the Informix ClientSDK 3.70 on Ubuntu. I've set the $INFORMIXDIR environment variable into /etc/profile and into the PATH variable to the bin directory. The installation dir was /opt/IBM/informix . When I now try to write code in PHP like
try{
$db = new PDO("informix:host=xx.xx.com;database=xxx;server=xxx_net; protocol=onsoctcp;", databaseuser, databasepassword);
$db->setAttribute(PDO::ATTR_ERRMODE, PDO::ERRMODE_EXCEPTION);
echo "test";
}catch (PDOException $e){
echo "<br/>Failed: ". $e->getMessage()."<br/>";
}
I've got the following error in the browser:
Failed: SQLSTATE=HY000, SQLDriverConnect: -23101 [Informix]
[Informix ODBC Driver][Informix]Unspecified System Error = -23101.
If I'm trying to connect with the Server Studio on Ubuntu to the Informix DB it works well, but I guess they are using the JDBC driver.
If I go to the bin directory of my Informix clientsdk, there is an application called finderr. If I do a finderr -23101 I get the following output:
./finderr -23101
-23101 Unable to load locale categories.
So i thought that I have to set the DB_LOCALE, CLIENT_LOCALE environment variables... my server is using en_us.819 and my client is using en_us.utf8 .
Being unable to load locale categories normally means that either INFORMIXDIR is not set for the software trying to access the Informix locale data (which is found in $INFORMIXDIR/gls), or that the locale categories are unspecified or mis-specified. These are classically the environment variables CLIENT_LOCALE and DB_LOCALE, which have values such as 'en_us.8859-1' (the default) or 'es_es.utf8' (Spanish in Spain using UTF-8).
I would concentrate on ensuring that the browser has the environment set correctly. It may depend on how you launch it.
There are some other environment variables that could be used - DBLANG, LANG, and the LC_* set of names. However, they are unlikely to be needed if CLIENT_LOCALE and DB_LOCALE are set. With that said, I've recently found that with Informix 4GL (I4GL), some code written with Japanese characters in things like table names would not compile unless DBLANG was set as well as the *LOCALE variables. However, the LC* and LANG variables seemed to have minimal to no effect on the result.
You probably have to set LD_LIBRARY_PATH. I do it with:
export LD_LIBRARY_PATH=$INFORMIXDIR/lib/:$INFORMIXDIR/lib/cli:$INFORMIXDIR/lib/esql:
export PATH=$INFORMIXDIR/bin:$INFORMIXDIR/lib:/usr/local/bin:/usr/bin:/bin
If that will not help then you can try with unixODBC. It seems that PHP uses some kind of ODBC. In unixODBC online manuals there is article about connecting to Informix - read it. Use isql (interactive SQL) unixODBC tool to connect to configured ODBC database.
If isql cannot connect to database with the same error then you can use strace to see what library the ODBC driver cannot load.
On the latest Ubuntu, I have a functioning PHP 5.2.4 installation. I want to use a remote Oracle server from PHP using OCI.
I've downloaded the "Instant Client Package - Basic Lite" (Link). I've unzipped the package containing the OCI libraries to a dir but I have no idea how to tell PHP that I want to use these libraries. Predictably, I get
Fatal error: Call to undefined function oci_connect() in...
when running this code:
<?php
$conn = oci_connect('hr', 'hrpw', 'someremotehost');
?>
I don't want to recompile PHP with Oracle support. What's the fastest way to wire up PHP so that I can use Oracle? Do I need any other libaries, like the Oracle client if I want to connect to a remote Oracle instance?
You need the PHP extension, try the following on your Ubuntu:
(sudo) pecl install oci8
Make sure your php.ini's (there should be one for your Apache and one for cli php) contain extension=oci8.so afterwards. Finally, you have to restart Apache and can confirm via <?php phpinfo(); ?> that the extension is loaded.
UPDATE:
Enter something like this when it asks you for ORACLE_HOME:
instantclient,/opt/oracle/instantclient
I think setting the environment variable would be another solution. /opt/oracle... is the path I put my instantclient in. I followed some tutorial a while ago, unfortunately I can't find it anmore.
HTH
I think you'll need to make sure that the $ORACLE_HOME/lib32 is in your $LD_LIBRARY_PATH, or else add that directory to the /etc/ld.so.conf file.
In the end, I downloaded Zend Core for Oracle and that worked.
http://www.zend.com/en/products/core/for-oracle