PHP application connect with external firebird database - php

I have an Ubuntu server (LAMP)
Now I want to connect with an external firebird database. How can I do that?
Can I install a firebird driver? How can I install a firebird driver?
Do I have to modify my php.ini file?

I do not use PDO
#apt-get install php5-interbase
You do not need to install firebird on local machine
PHP sample code
$dbh = ibase_pconnect("remote_server_ip:db_file", "user_name", "user_password") or die('die message');
$q = ibase_query($dbh, "select * from some_table");
while ($r = ibase_fetch_object($q)) {
$some_value = $r->SOME_FIELD;
echo $some_value;
}

Related

Connect to SQL Server from CakePHP 3 on Ubuntu 12.04 LTS

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);

MongoClient not found when put on server

I have installed and successfully connected to MongoDB from my local machine. When I ran the site which uses it from my localhost it has no problem connecting to it, but when I upload the folder to a FTP client and connect to a web hosting and domain it says MongoClient class not found.
Should I change something in the config.php file? Now it looks like this:
<?php
$conn = new MongoClient();
$data = $conn->db;
?>
Install Mongodb Extension with:
apt-get install php-pear php5-dev
pecl install mongo

PHP PDO installation on windows (xampp)

I am trying to develop a web app that can connect to as many different databases as possible on PHP. PDO (http://www.php.net/manual/en/book.pdo.php) seems to be the right interface for it but I am having trouble installing all the extentions needed for all the different PDO database drivers that I need.
Please note that I use xampp on a windows 7 machine. PHP Version 5.3.8. PDO drivers enabled mysql, odbc, sqlite, sqlite2, sqlsrv.
I have successfully connected with the following:
MySQL using PDO_MYSQL [MySQL (PDO) ] (extension seemed to be installed on xampp by default)
Microsoft SQL Server using PDO_SQLSRV [MS SQL Server (PDO)] (followed the instractions on http://craigballinger.com/blog/2011/08/usin-php-5-3-with-mssql-pdo-on-windows/)
I had no luck installing or connecting with:
(SOLVED SEE BELOW UPDATES) Sybase (I tried to use and install PDO_DBLIB [MS SQL Server (PDO)]but with no luck)
(SOLVED SEE BELOW UPDATES)Oracle (I tried to enable the extension=php_pdo_oci.dll in php.ini with the dll that was installed with xampp after restarting Apache the server failed to start. Was trying to use PDO_OCI [Oracle (PDO)])
I know I can work around those 2 with using the database specific drivers but I would really love to use PDO for everything that I need.
Does anyone know how to install and enable PDO_DBLIB and PDO_OCI drivers or a windows machine, or any other way of connecting with Sybase and Oracle databases using PDO?
UPDATE
Just succesfully connected with oracle with PDO_OCI. What you need to do is the following:
Download and install the proper Oracle Instant Client on your windows machine for
example instantclient_12_1 and add its path to PATH in SYSTEM
Environmental Variables. Note Oracle supports only 2 versions down so select
your client version properly. Do that and then restart your Apache. Note that the connection string is very different from here is a sample of what I used:
$tns = "(DESCRIPTION=(ADDRESS_LIST = (ADDRESS = (PROTOCOL = TCP)(HOST = ".$myServer.")(PORT = 1521)))(CONNECT_DATA=(SID=".$myDB.")))";
$connStr = "oci:dbname=".$tns;
$conn = new PDO($connStr,$myUser,$myPass);
UPDATE
Just connected with Sybase as well with PDO_ODBC. What you need is the following:
Must have Sybase ASE ODBC Driver which comes with the SDK. Find below the connection string used:
$connStr = "odbc:Driver={Adaptive Server Enterprise};server=".$myServer.";port=".$myPort.";db=".$myDB;
$conn = new PDO($connStr,$myUser,$myPass);
So i finally managed to connect to four database here's how I managed:
MySQL using PDO_MYSQL extension seemed to be installed on xampp by default didn't have to do much work. Here is the code I used for the connection:
$connStr = "mysql:host=".$myServer.";dbname=".$myDB;
$conn = new PDO($connStr,$myUser,$myPass);
Microsoft SQL Server using PDO_SQLSRV followed the instructions on http://craigballinger.com/blog/2011/08/usin-php-5-3-with-mssql-pdo-on-windows/. Here is the code I used:
$connStr = "sqlsrv:Server=".$myServer.";Database=".$myDB;
$conn = new PDO($connStr,$myUser,$myPass);
Oracle with PDO_OCI. Download and install the proper Oracle Instant Client on your windows machine for example instantclient_12_1 and add its path to PATH in SYSTEM Environmental Variables. Note Oracle supports only 2 versions down so select your client version properly. Do that and then restart your Apache. Here is the code I used:
$tns = "(DESCRIPTION=(ADDRESS_LIST = (ADDRESS = (PROTOCOL = TCP)(HOST = ".$myServer.")(PORT = 1521)))(CONNECT_DATA=(SID=".$myDB.")))";
$connStr = "oci:dbname=".$tns;
$conn = new PDO($connStr,$myUser,$myPass);
Sybase with PDO_ODBC Must have Sybase ASE ODBC Driver which comes with the SDK. Here is the code I used:
$connStr = "odbc:Driver={Adaptive Server Enterprise};server=".$myServer.";port=".$myPort.";db=".$myDB;
$conn = new PDO($connStr,$myUser,$myPass);

How can I use php's built in http server + mysql?

I'm trying to connect to mysql server using the following code:
$connection = mysql_connect("localhost", "username", "password");
if(!$connection)
{
die('Could not connect: '. mysql_error());
}
And I'm getting "Call to undefined function mysql_connect()". Why is that? isn't this function built in in php?
I'm using Ubuntu 12.04 + php 5.4.11 + php's built in http server.
First do not use mysql_* functions as those functions are deprecated
and second you need to install php5-mysql
sudo apt-get install php5-mysql
and then you can use mysqli and also PDO (needs to be installed too).
You must enable the extension.
Be aware that this API is deprecated.

Linux based PHP install connecting to MsSQL Server

What is the best way to connect via PHP on a Linux box to a Remote Microsoft SQL Server.
The PHP will only ever run on a Linux box.
I've been trawling for the simplest answer for a while now.
Php 5.6
Ubuntu
sudo apt-get install php5.6-sybase freetds-common libsybdb5
AWS / Centos / Redhat
sudo yum install php56-mssql
After that, you can connect to the MsSql database through PHP with something like this:
<?php
$server = 'localhost';
$user = 'someUser';
$pass = 'somePassword';
$database = 'theDatabaseName';
try {
$pdo = new \PDO(
sprintf(
"dblib:host=%s;dbname=%s",
$server,
$database
),
$user,
$pass
);
$pdo->setAttribute(PDO::ATTR_ERRMODE, PDO::ERRMODE_EXCEPTION);
} catch (PDOException $e) {
echo "There was a problem connecting. " . $e->getMessage();
}
$query = "SELECT * FROM TestSchema.Employees";
$statement = $pdo->prepare($query);
$statement->execute();
$results = $statement->fetchAll(PDO::FETCH_ASSOC);
var_dump($results);
You can troubleshoot MsSQL with something like this on the command line:
tsql -H your.server.name -p 1433 -U yourusername -P yourpassword -D yourdatabasename
To install tsql you can run this:
Installation of SQL binaries for testing on any PHP version
sudo apt install freetds-bin
Php 7+
Microsoft has native drivers we can use. Full instructions are here (Redhat / Ubuntu / Others).
That link also contains required steps to install Ms SQL server on your dev machine (working on Ubuntu, doesn't work on AWS, but you can just spin up an RDS instance there).
It also contains basic instructions on how to create test tables and data in the database, and PHP connectivity code.
You can also install the components for a newer version of PHP like this:
sudo apt-get install php7.2-sybase freetds-common libsybdb5
you must to install mssql driver for php on linux.
this is a best tutorial for you.
Try: For Ubuntu
sudo apt-get install php5-sybase php5-odbc freetds-common
Edit freetds.conf then connect MSSQL server with this PHP.
After searching and trying out the many suggestions here and in other posts, and spending a lot of time, a colleague suggested trying ADO.
As we already had an ADO enabled PHP install, it literally took less than 10 minutes to get up and running.
If your serious about connecting from Linux PHP to MS-SQL, consider ADO.
It's interesting to note that every answer here proposes one solution to the problem rather than answering the question asked which was which is the "best" solution. Unfortunately the OP forgot to tell us what the criteria were for "best".
Nobody so far has mentioned odbc. While this entails both configuring the odbc driver for connecting to the database and enabling the php extension, this method provides the best isolation of the php code from the underlying database making it easier to port the code later.
The microsoft provided drivers for php should give good compatibility but only support v7 up of php.
You may prefer to stick with the functionality provided by your Linux distro to ensure you have a supportable product and/or automated patch management. An alternative to odbc here may be the freetds driver but you didn't tell us anything about which Linux distro this is.
Get the sqlsrv extension from microsoft for php http://msdn.microsoft.com/en-us/sqlserver/ff657782.aspx

Categories