Connecting to SQL Server from Laravel - php

I'm new to SQL Server and I try to connect from PHP to my SQL Server; I've already extracted SQL Server extra into php/ext:
And after that I try to put extension into php.ini
but I always get this error:
How can I solve this? The driver never been installed then

Related

Cannot connect to Databricks SQL Endpoint using PHP and ODBC

I am trying to connect to our Databricks SQL endpoint using PHP in a Docker container.
I setup my Docker container to download and configure the ODBC driver as specified here: https://docs.databricks.com/integrations/bi/jdbc-odbc-bi.html#install-and-configure-the-odbc-driver-for-linux
My Docker setup is at https://github.com/rlorenzo/databricks_php
However, when it try to connect using ODBC from my PHP test script I get the error:
Warning: odbc_connect(): SQL error: [unixODBC][FreeTDS][SQL Server]Unable to connect to data source, SQL state S1000 in SQLConnect in /test_connection.php on line 14
ODBC connect failed: S1000
When I try to connect using the PDO library I get a different error message:
SQLSTATE[08S01] SQLConnect: 20009 [unixODBC][FreeTDS][SQL Server]Unable to connect: Adaptive Server is unavailable or does not exist
The connection details are correct because I was able to connect to the Databricks SQL endpoint using Datagrip. I can also verify that the ODBC library is properly installed because I can query a Microsoft SQL Server.
I must have the Databricks ODBC Connector misconfigured somehow, but I am clueless. From my view everything matches the documentation.
I have tried contacting Databricks support, but they have been unhelpful so far.
The problem was that the Databricks SQL driver does not yet support ARM, which my laptop and Docker container was building for. See ('01000', "[01000] [unixODBC][Driver Manager]Can't open lib '/opt/simba/spark/lib/64/libsparkodbc_sb64.so' : file not found (0) (SQLDriverConnect)")
I updated my repo at https://github.com/rlorenzo/databricks_php with a working example and forced the container to build an x86 version.
Will update my repo if Databricks ever supports ARM.
Hope this helps someone in the future.

SQL server error: Unable to connect to your database server using the provided settings

Again I am here with an error, i have connected my PHP with SQL server from an IP Address and it works properly in my local PC. but when i transfer my source codes to my client PC it gives below error:
A Database Error Occurred
Unable to connect to your database server using the provided settings.
Filename: C:/xampp/htdocs/SAT_POS/system/database/DB_driver.php
Line Number: 436
but actualy i have included the extension also and set in php.ini, see below:
extension=php_sqlsrv_56_ts.dll
extension=php_sqlsrv_54_ts.dll
the above two lines are included in the php.ini file and the extension directory is also the default one, see below:
extension_dir="C:\xampp\php\ext"
and in CI database code I configured like below :
You have to pick ONE SQL Server database extension ONLY.
You have also loaded one extension that is compiled for PHP 5.4
php_sqlsrv_54_ts.dll
AND one that is compiled for PHP 5.6
php_sqlsrv_56_ts.dll
Pick the ONE extension that matches your currently runnning PHP version
Also did you load the SQLServer client software on your clients PC.
At last with the help of the stack genius who commented on this I have done the work!
Just installed ODBC DRIVER for SQL SERVER on the windows!

LOAD DATA LOCAL INFILE does not work from php 5.5 using PDO

I've recently moved web servers, and the new web server has a different version of PHP.
New Server: PHP 5.5.3-1ubuntu2 (cli)
Old Server: PHP 5.3.10 (cli)
On the database server, my.cnf is set to allow local-infile.
I can use load data local infile from:
- HeidiSQL
- The command line client running on the new web server using --local-infile=1
- PHP, using PDO, from the old web server
However, when I try to connect from the new web server, using PHP with PDO, I get:
A database problem has occurred: SQLSTATE[42000]: Syntax error or access violation: 1148 The used command is not allowed with this MySQL version
php.ini:
[MySQL]
; Allow accessing, from PHP's perspective, local files with LOAD DATA statements
; http://php.net/mysql.allow_local_infile
mysql.allow_local_infile = On
PDO constructor:
$this->db_conn = new PDO("mysql:host=$host;dbname=$dbname;port=$port", $user, $pass, array(PDO::MYSQL_ATTR_LOCAL_INFILE => 1));
I've also tried ini_set('mysql.allow_local_infile', 1) and ini_set('mysql.allow_local_infile', true) in the PHP script.
The LOCAL keyword is needed because the files are hosted on the web server, not the database server.
What else does PHP 5.5 want from me?
You need to configure both the client and the server to allow this command:
Make sure the server allows LOAD DATA LOCAL INFILE. Edit /etc/my.cnf on the MySQL server:
[server]
local-infile=1
Set the PDO attribute in your PHP script:
<?php
$dsn = "mysql:host=localhost;dbname=test";
$user = "root";
$password = "root";
$pdo = new PDO($dsn, $user, $password, array(PDO::MYSQL_ATTR_LOCAL_INFILE=>1));
$pdo->setAttribute(PDO::ATTR_ERRMODE, PDO::ERRMODE_EXCEPTION);
$pdo->exec("LOAD DATA LOCAL INFILE 'foo.csv' INTO TABLE foo FIELDS TERMINATED BY ','");
This needs to be set in the driver options argument to the constructor, not in a subsequent call to setAttribute().
I just tested the above code example successfully with PHP 5.5.8 and Percona Server 5.6.15 on CentOS Linux 6.5.
If you still have trouble, you may have a build of the MySQL client or PDO that does not permit local-infile. The requirements are described in http://dev.mysql.com/doc/refman/5.6/en/load-data-local.html
The mysql.allow_local_infile option in your php.ini is not relevant to PDO.
Your code is absolutelty correct no need to change as the error lies in your database file.
error cause
The reason of your error caused as you have created the database backup through commandline and trying to upload data through custom php script.
solution
There are 2 solutions available to resolved the issue are:-
Try to load database through commandline and if you dont have access to commandline then you can ask your service provider to do upload for you. As he has to just run simple command.
Open the databse file in text editor and check the headers which encoding is used. Then read the data and de-encode it then run the insert command.
If the problem doesnt resolve then let me know..

db2_connect to as400 with php and wamp server

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?

Want to connect PHP5 to MS SQL SERVER 2005

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

Categories