UPDATE: This question has been flagged as a question that has been solved already. But when checked, those previous "similar" questions require users to download the corresponding .dll file which is not applicable for macOS users and other answers did not explicitly elaborate on how to install needed extensions like pdo_sqlsrv, sqlsrv, and ODBC for XAMPP-installed PHP.
I'm trying to connect to MS SQL database using CodeIgniter 3.1.9 via ODBC:
$db['default'] = array(
'dsn' => '',
'hostname' => 'x.x.x.x',
'username' => 'sa',
'password' => 'xxx',
'database' => 'xxx',
'dbdriver' => 'odbc'
But I'm getting this error:
An uncaught Exception was encountered
Type: Error
Message: Call to undefined function odbc_connect()
Filename: /Applications/XAMPP/xamppfiles/htdocs/gpweb/system/database/drivers/odbc/odbc_driver.php
Line Number: 141
PHP is installed via XAMPP. I checked the php.ini file to get information about ODBC and the line below is disabled because of the semi-colon in the beginning:
;extension=php_pdo_odbc.dll
I know it is irrelevant because I'm running on MacOS and .dll files are for Windows (but I still tried enabling it and with more errors):
A PHP Error was encountered
Severity: Core Warning
Message: PHP Startup: Unable to load dynamic library '/Applications/XAMPP/xamppfiles/lib/php/extensions/no-debug-non-zts-20160303/php_pdo_odbc.dll' - dlopen(/Applications/XAMPP/xamppfiles/lib/php/extensions/no-debug-non-zts-20160303/php_pdo_odbc.dll, 0x0009): tried: '/Applications/XAMPP/xamppfiles/lib/php_pdo_odbc.dll' (no such file), '/Applications/XAMPP/xamppfiles/lib/php/extensions/no-debug-non-zts-20160303/php_pdo_odbc.dll' (no such file)
Filename: Unknown
Line Number: 0
Has anyone encountered this issue before and how did you solve it? How can you enable ODBC in MacOS with PHP installed using XAMPP?
I found the solution, missing in php.ini
extension=php_odbc.dll
Unfortunately, macOS users that use XAMPP to install PHP have no way to install extensions like sqlsrv, pdo_sqlsrv, and ODBC, unlike in Windows, where they can download the necessary .dll files and enable extensions in the php.ini.
I've been using CodeIgniter 3.x.x for years to create web applications and MySQL as the database. I wanted to utilize the said PHP library with my other projects requiring MSSQL as the database since CI can do so, provided that you have installed the necessary extensions.
I have scoured the internet and there is really no definite solution to install extensions in XAMPP-installed PHP running macOS.
I gave up and installed PHP using homebrew instead. In your terminal, enter:
$ brew install php
Then installed sqlsrv extension (for M1 ARM64 users)
sudo CXXFLAGS="-I/opt/homebrew/opt/unixodbc/include/" LDFLAGS="-L/opt/homebrew/lib/" pecl install sqlsrv
sudo CXXFLAGS="-I/opt/homebrew/opt/unixodbc/include/" LDFLAGS="-L/opt/homebrew/lib/" pecl install pdo_sqlsrv
Then the ODBC extension:
HOMEBREW_NO_ENV_FILTERING=1 ACCEPT_EULA=Y
brew install msodbcsql17 mssql-tools
Since I cannot use the XAMPP-installed PHP, I have to use the CodeIgniter 4 to use the natively installed PHP:
composer create-project codeigniter4/appstarter project-root
After that, in the /project/app/Config/Database.php of my CodeIgniter 4 project, setup the connection to the database:
public $default = [
'DSN' => '',
'hostname' => 'x.x.x.x', // IP ADDRESS OF THE SQL SERVER
'username' => 'xxx', // USERNAME
'password' => 'xxx', // PASSWORD
'database' => 'xxx', // NAME OF DATABASE
'DBDriver' => 'SQLSRV', // DATABASE DRIVER TO BE USED
'DBPrefix' => '',
'pConnect' => false,
'DBDebug' => (ENVIRONMENT !== 'production'),
'charset' => 'utf8',
'DBCollat' => 'utf8_general_ci',
'swapPre' => '',
'encrypt' => false,
'compress' => false,
'strictOn' => false,
'failover' => [],
'port' => 1433, // DEFAULT PORT FOR SQL SERVER
];
This is not the solution to the original problem (XAMPP-installed PHP), but an alternative solution to connect to MSSQL database using PHP.
REFERENCE:
https://learn.microsoft.com/en-us/sql/connect/php/installation-tutorial-linux-mac?view=sql-server-ver16
https://www.codeigniter.com/user_guide/installation/index.html
But still, if you found a way to install sqlsrv and ODBC extensions in XAMPP-installed PHP running macOS, please don't hesitate to post it here.
Related
First of all, the problem is about Laravel not postgresql or PHP. I can connect postgresql with a simple PHP file. But Laravel can't do it somehow.
When I try to connect postgresql server in my computer with laravel I get "PDOException with message 'could not find driver'" error. I am getting this error when I run DB::connection()->getPdo(); command at artisan tinker.
If I run php artisan migrate command, the error is Illuminate\Database\QueryException : could not find driver (SQL: select * from information_schema.tables where table_schema = public and table_name = migrations and table_type = 'BASE TABLE')
My configuration is below:
Windows 10
Wamp Server 3.1.4
Apache 2.4.35
PHP 7.2.10
Laravel Framework 6.0.3
Related lines of Laravel .env file:
DB_CONNECTION=pgsql
DB_HOST=127.0.0.1
DB_PORT=5432
DB_DATABASE=laravel_dnm1
DB_USERNAME=postgres
DB_PASSWORD=mrd.BE.265
Related lines of Laravel database.php file:
'default' => env('DB_CONNECTION', 'pgsql'),
...
'pgsql' => [
'driver' => 'pgsql',
'url' => env('DATABASE_URL'),
'host' => env('DB_HOST', '127.0.0.1'),
'port' => env('DB_PORT', '5432'),
'database' => env('DB_DATABASE', 'forge'),
'username' => env('DB_USERNAME', 'forge'),
'password' => env('DB_PASSWORD', ''),
'charset' => 'utf8',
'prefix' => '',
'prefix_indexes' => true,
'schema' => 'public',
'sslmode' => 'prefer',
],
When I run print_r(PDO::getAvailableDrivers()); at my server I get below output:
Array ( [0] => mysql [1] => pgsql [2] => sqlite )
Related lines of php info is below:
NOTE: There is no problem when I use mysql instead of postgresql.
NOTE2: I can connect the DB when I use regular PHP. Only Laravel gives this error.
install postgresql
sudo apt-get install php-pgsql
then uncomment pgsql and pdo-pgsql extensions in etc/php/$PHP_VERSION/apache2/php.ini file
then restart apache2
Verify your PHP version with php -v
Install php7.2-pgsql when needed.
I solved the issue. It is a bug at WAMP I think. When I edit php.ini from WAMP's menu it opens a different php.ini than active PHP version's. So I opened php.ini from file system and edited it from there.
There are different php version installed on your WAMP SERVER. when you click on WAMP icon it will show that pgsql and pdo_pgsql are active but for different php version. You need to check your php version using php -v command and then go to the WAMP folder and find that php version and edit php.ini file and enable pgsql extensions there.
This question already has answers here:
mysqli_real_connect(): (HY000/2002): No such file or directory
(19 answers)
Closed 5 months ago.
I had uploaded my website to server and then I tried to access, but the code igniter returns me that error that I don't find any answer. Why is this happening?
My config database is set like:
$db['default'] = array(
'dsn' => '',
'hostname' => 'localhost',
'username' => 'netservice',
'password' => '*********',
'database' => 'valedastrutas',
'dbdriver' => 'mysqli',
'dbprefix' => '',
'pconnect' => FALSE,
'db_debug' => FALSE,
'cache_on' => FALSE,
'cachedir' => '',
'char_set' => 'utf8',
'dbcollat' => 'utf8_general_ci',
'swap_pre' => '',
'encrypt' => FALSE,
'compress' => FALSE,
'stricton' => FALSE,
'failover' => array(),
'save_queries' => TRUE,
);
MySQL connection driver does not get any meaningful server at the location of localhost. So use,
'hostname' => '127.0.0.1'
rather than
'hostname' => 'localhost'
I've got this error
mysqli::real_connect(): (HY000/2002): No such file or directory
from PhpMyAdmin running on my Mac Mojave, with MySQL server also running on my Mac.
Fixed it by editing PhpMyAdmin/config.inc.php and changed the line:
$cfg['Servers'][$i]['host'] = 'localhost';
to
$cfg['Servers'][$i]['host'] = '127.0.0.1';
in phpmyadmin version 5.1.0 all lang., the config. file is located in libraries/config.default.php
do the following change:
$cfg['Servers'][$i]['host'] = 'localhost';
to
$cfg['Servers'][$i]['host'] = '127.0.0.1';
Same problem occurd with me, with AWS RDS MySQL. Looked various sources, but as of this thread, almost all lack of answer.
While this answer helped me, tweak in mind to update hostnames at server. Access your SSH and follow the steps:
cd /etc/
sudo nano hosts
Now, Appending here your hostnames: For example:
127.0.0.1 localhost
127.0.0.1 subdomain.domain.com [if cname redirected to endpoints]
127.0.0.1 xxxxxxxx.xxxx.xxxxx.rds.amazonaws.com [Endpoints]
and now, configuring config/database.php as follows:
$active_group = 'default';
$query_builder = TRUE;
$db['default'] = array(
'dsn' => '',
'hostname' => '35.150.12.345',
'username' => 'user-name-here',
'password' => 'password-here',
'database' => 'database-name-here',
'dbdriver' => 'mysqli',
'dbprefix' => '',
'pconnect' => FALSE,
'db_debug' => TRUE,
'cache_on' => FALSE,
'cachedir' => '',
'char_set' => 'utf8',
'dbcollat' => 'utf8_general_ci',
'swap_pre' => '',
'encrypt' => FALSE,
'compress' => FALSE,
'stricton' => FALSE,
'failover' => array(),
'save_queries' => TRUE
);
where 35.150.12.345 is your IPv4 Public IP, located at ec2-dashboard > Network Interfaces > Description : RDSNetworkInterface >> IPv4 Public IP('35.150.12.345') there.
Note: Please note that only IPV4 will work at 'hostname' option. hostname, cname, domains will output database connection error.
In my case restarting mysql was needed as it had stopped running
If the error is due to the MySQL service being dead, you can restart it with this command:
sudo service mysql restart
If the error occured after restarting the server, then you may also need to enable MySQL at startup:
sudo systemctl enable mysql
Also had this problem. The only solution that helped me - first to stop mysql server by the command "service mysql stop" and than run start lampp again: "sudo /opt/lampp/lampp start".
I had this same problem. I was using a host defined in my /etc/hosts file:
127.0.0.1 test.localhost
and connecting with the url http://test.localhost/index.php/news/view as in the tutorial. I got that error, and only fixed it by changing the line:
'hostname' => 'localhost',
to:
'hostname' => 'test.localhost',
I suggest you enable and look at the detailed php_errors.log
Check that the directory specified using session.save_path in php.ini exists and is writable. You can use phpinfo() to show the actual session.save_path.
Creating the missing "phptmp" directory specified as session.save_path fixed this issue for me.
I had the same issue, in my case the site was up an running fine for a long time. Since lots of answers here concern a first time install and use I decided to tackle the same issue for systems that already function properly for a while then suddenly give this error.
First I think is important to understand the issue. As far as I know (and I may be wrong) this issue comes up if the driver cannot secure a connection to the database. This can be caused by many things, including the database being down for any issue or maintenance.
In my case the issue was caused as I accessed the website during a MySQL update (Software Updater was running in the background updating MySQL components). So I had to wait for the update to complete, then the website was again up and running with no issues.
So keep this aspect in mind, too.
None of the other answers worked for me. I have MySQL 8.0.22 installed on my Mac OS 10.14.6, works fine from the command line. However, what I had done is chosen the stronger password encryption when I upgraded MySQL. This was the problem, not the localhost config. The config.inc.php can point to either 'localhost' or '127.0.0.1'. Once I got phpMyAdmin running, I confirmed this by using both.
The way to fix this (for me) was to click on Mac system preferences and choose MySQL. Click Initialize Database, and switch over to "Legacy password encryption". Restart and everything works fine. MySQL restarts, phpMyAdmin at http://localhost/phpmyadmin let me log in no problems.
I'm waiting to upgrade the Mac to OS 15 once I'm sure I won't brick the silly thing.
I'm trying to install Zend Framework 2 + Doctrine from this manual and have some problem with PDO driver. Doctrine is trying to connect to my MySQL server and then trying to create schema:
./vendor/bin/doctrine-module orm:schema-tool:create
I have this error:
[PDOException]
could not find driver
This is my config/autoload/doctrine.local.php:
return array( 'doctrine' => array(
'connection' => array(
'orm_default' => array(
'driverClass' =>'Doctrine\DBAL\Driver\PDOMySql\Driver',
'params' => array(
'driver' => 'pdo_mysql',
'host' => 'localhost',
'port' => '3306',
'user' => 'root',
'password' => 'password',
'dbname' => 'blog',
)))));
I have PHP 5.3.5 and i have uncommented ;extension=php_pdo_mysql.dll in php.ini, also it wasn't commented. But php -m | grep -i pdo gives me:
PDO
only. I'm know that it should be pdo_mysql too, but i'm trying everything and it isn't appear.
Anyway, PDO driver is works well at my another project on this server, where I'm not using Zend and Doctrine.
Ohh yes. I'm just solved a problem. I'm going to this page and thought to find my php.ini files anywhere else perhaps PHP folder - it was one more in "C:\Users\%username%\AppData\Local\VirtualStore\Program Files (x86)\wamp\bin\php\php5.3.5" and there row
;extension=php_pdo_mysql.dll
weren't uncomment. I'm uncommented it and it works!
I'm trying to connect to pgsql via laravel and finally got everything setup (pgsql server running, pdo installed, all libs installed). I'm running on a VPS (CentOS) managed via CPanel/WHM.
Here's what I'm doing:
I'm trying to create a user database via artisan (Laravel's command line) using migrate:install.
For those that don't use Laravel, artisan uses php's PDO for pgsql to connect. Here are my settings:
'pgsql' => array(
'driver' => 'pgsql',
'host' => 'localhost',
'database' => 'dbname',
'username' => 'username',
'password' => 'password',
'charset' => 'utf8',
'prefix' => '',
),
I've also setup a test.php file:
$dbconn = pg_connect("host=localhost port=5432 dbname=dbname user=username password=password");
which also fails. I used phpPgAdmin to see what's up and all of the permissions are set correctly, the database shows up, the username is correct, same with password. I checked where postgre (version 8.4.12 btw) was running and phpPgAdmin tells me "localhost:5432".
The error I get via the command line is the following:
SQLSTATE[08006] [7] FATAL: no pg_hba.conf entry for host "::1", user "myusername", database "my_database", SSL OFF
Now, I tried to find the pg_hba.conf file but I'm not entirely sure where to look for it. Same goes for the error/access logs for pg and google hasn't been any help as far as this goes.
Any idea on what I can do?
localhost points to IPV6 ::1 address on your system. Postgresql makes the difference between ipv6 and ipv4 addresses when dealing with access list.
I was able to install/configure everything correctly. I changed the "host" to 127.0.0.1, not sure why that made a difference but it did :)
we already have a Moodle installation working in this scenario: linux + php5 + freetds + sql server.
but we just can't figure out how to link drupal 7 to sql server in the same manner.
what configs should we use? anyone ever tried this?
drupal simply does not show up in the available databases list.
note: we are already able to connect php to sql server using freetds, but just can't figure out how to do this on Drupal 7.
You can't use sqlsrv module on Linux because it requires PDO_SQLSRV driver that works only on Windows (see this comment)
To use FreeTDS you will need to write a Drupal Database Driver by yourself (similar with sqlsrv). Or don't use the database abstraction layer at all and do the call by yourself inside your module (if you only need MS SQL for parts of you project.
The good news (I hope) is that you can install dblib driver (in Ubuntu: sudo apt-get install php5-mssql) and use the sandbox project. A little info regarding this sandbox projects you can find in author's comment here. How to use it in you settings.php file can be seen here.
dblib database support in Drupal is still experimental, so test it before using it.
No you can't, but you can use drupal odbc driver which works the same way but connect through odbc (https://www.drupal.org/sandbox/pstewart/2010758), all you have to do is to install it (including its server requirement) and change your configuration to something like this (tested on Drupal 7 on Ubuntu Server) :
'external' =>
array (
'default' =>
array (
'odbc_driver' => 'FreeTDS',
'database' => '',
'username' => '',
'password' => '',
'host' => '',
'port' => '1433',
'driver' => 'odbc',
'prefix' => ''
),
),