Call to undefined function odbc_connect() in Ubuntu - php

I am trying to connect with PHP to SQL server. I have installed Microsoft ODBC Driver 13 for SQL Server and I have test it using 'isql' command. Now when I am trying to connect to the server in PHP it always crashes and says "http error 500". Here is the code:
<?php
$server = merkur.edikt.local;
$database = ITServiceE;
$connection = odbc_connect("Driver={ODBC DRIVER 13 for SQL Server};
Server=$server;Database=$database;",
'user',
'PW'
);
echo "connected";
?>
I am using Ubuntu 16.04 server and Apache2 and PHP 7.
I think it might be problem with permissions for the Apache(if the Apache can access the ODBC Driver) but I am not really sure how this works.
EDIT:
Here is the log from Apache errors:
PHP Notice: Use of undefined constant merkur - assumed 'merkur' in /var/www/html/index.php on line 2
PHP Notice: Use of undefined constant edikt - assumed 'edikt' in /var/www/html/index.php on line 2
PHP Notice: Use of undefined constant local - assumed 'local' in /var/www/html/index.php on line 2
PHP Notice: Use of undefined constant ITServiceE - assumed 'ITServiceE' in /var/www/html/index.php on line 3
PHP Fatal error: Uncaught Error: Call to undefined function odbc_connect() in /var/www/html/index.php:4\nStack trace:\n#0 {main}\n thrown in /var/www/html/index.php on line 4
and the file odbc.ini is empty and odbcinst.ini looks like this:
[ODBC Driver 13 for SQL Server]
Description=Microsoft ODBC Driver 13 for SQL Server
Driver=/opt/microsoft/msodbcsql/lib64/libmsodbcsql-13.0.so.0.0
Threading=1
UsageCount=2

Call to undefined function odbc_connect() means that your PHP system doesn't have any function with that name.
Since it isn't a user function written in pure PHP but a function from a PHP extension, that means that you haven't installed such extension. It's worth noting that the PHP extensions is not the same as the SQL Server driver (you need both).
Your code also contains some undefined constants which I guess are meant to be strings. I strongly recommend you enable full error reporting in your development box so you don't need to check the error logs to learn about simple errors.

Related

connecting php to oracle 19c db

Trying to connect to oracle 19c from php the server is not on the same machine as the php, I have so far installed instant client 19_15, added it as a environment variable, and then in the php.ini file I have taken off the semi colon for both the files extension=oci8_19 and extension=pdo_oci not sure what else to do to make the php to connect to the oracle db.
some error messages I have been getting are: PDO: connection failed: could not find driver
and from oci_connect: Fatal error: Uncaught Error: Call to undefined function oci_connect() in Stack trace: #0 {main} thrown in on line 7
p.s. architecture is x64, php version is 8.1.8 and using apache24 lounge

oci_connect() can't connect - command Line with codeigniter

Although calling the same script through browser work fine, trying to trigger the same script via CLI didn't work!
The way I have to call the script I use CodeIgniter structure :
php index.php controller/function/parameter
I have also change in config file of my project:
$config['uri_protocol'] = 'AUTO'
But the problem that oci can't work within cli although it works by calling it using the browser.
THis error appear:
Fatal error: Call to undefined function oci_connect() in C:\wamp64\www\MYPROJECT\syst
em\database\drivers\oci8\oci8_driver.php on line 238
Severity: Error Message: Call to undefined function
oci_connect() Filename:
C:\wamp64\www\MYPROJECT\system\database\drivers\oci8\oci8_driver.php
Line Number: 238
I have enabled the oci extension at php.ini
extension=php_oci8_12c.dll
which is existed in the following directory:
C:\wamp64\bin\php\php5.6.19\ext\php_oci8_12c.dll

How to connect to MS SQL Server 2016 from PHP 7

I'm attempting to insert rows in table in a database hosted in MS SQL Server 2016 installed in my local computer.
Here is my snippet $dbc = mssql_connect('MwangiCJ-PC/mwangi','sqluser','xxxx','mydb');
I have tried out the answer from
mssql_connect() with PHP5 and MSSQL2012 Express but I still get the error Fatal error: Uncaught Error: Call to undefined function mssql_connect()
When i run a simple phpinfo() I can see that I already have both sqlsrv and pdo_sqlsrv available.
Am I missing anything else? Please help. Thank you.
From the PHP docs:
Warning
This function was REMOVED in PHP 7.0.0.
Alternatives to this function include:
PDO::__construct()
sqlsrv_connect()
odbc_connect()

Modx Evo - After copy from webserver to localhost manager login not possible anymore

I am using the latest WAMPServer64 with PHP 5.5.12.
What I did: From a webserver (runs PHP 5.4.16) I have copied the modx folders to localhost, then I copied the entire database. I have also changed the database credentials accordingly via manager/includes/confic.inc.php.
When opening the manager login, I see the following:
Deprecated: mysql_connect(): The mysql extension is deprecated and will be removed in the future: use mysqli or PDO instead in \manager\includes\extenders\dbapi.mysql.class.inc.php on line 93
When I try to login, the manager does not show up and I get a bunch of errors, content of php_error.log:
PHP Deprecated: mysql_connect(): The mysql extension is deprecated and will be removed in the future: use mysqli or PDO instead in manager\includes\extenders\dbapi.mysql.class.inc.php on line 93
PHP Stack trace:
PHP 1. {main}() manager\processors\login.processor.php:0
PHP 2. DBAPI->escape() manager\processors\login.processor.php:51
PHP 3. DBAPI->connect() manager\includes\extenders\dbapi.mysql.class.inc.php:156
PHP 4. mysql_connect() manager\includes\extenders\dbapi.mysql.class.inc.php:93
PHP Notice: Undefined index: captcha_code in manager\processors\login.processor.php on line 53
PHP Stack trace:
PHP 1. {main}() manager\processors\login.processor.php:0
PHP Notice: Undefined index: rememberme in manager\processors\login.processor.php on line 54
PHP Stack trace:
PHP 1. {main}() manager\processors\login.processor.php:0
PHP Notice: Undefined variable: allowed_ip in manager\processors\login.processor.php on line 134
PHP Stack trace:
PHP 1. {main}() manager\processors\login.processor.php:0
PHP Notice: Undefined variable: allowed_days in manager\processors\login.processor.php on line 148
PHP Stack trace:
PHP 1. {main}() manager\processors\login.processor.php:0
PHP Notice: Undefined variable: newloginerror in manager\processors\login.processor.php on line 224
PHP Stack trace:
PHP 1. {main}() manager\processors\login.processor.php:0
PHP Warning: Cannot modify header information - headers already sent by (output started at manager\processors\login.processor.php:54) in manager\processors\login.processor.php on line 298
PHP Stack trace:
PHP 1. {main}() manager\processors\login.processor.php:0
PHP 2. setcookie() manager\processors\login.processor.php:298
PHP Notice: Undefined variable: sql in manager\includes\extenders\dbapi.mysql.class.inc.php on line 276
PHP Stack trace:
PHP 1. {main}() manager\processors\login.processor.php:0
PHP 2. logHandler->initAndWriteLog() manager\processors\login.processor.php:302
PHP 3. logHandler->writeToLog() manager\includes\log.class.inc.php:42
PHP 4. DBAPI->insert() manager\includes\log.class.inc.php:76
I have searched for solutions on the net, some suggested to clear the cache, which is not directly possible since the manager interface does not load. I also tried to upgrade using the default install folder, same problem remains.
So if anyone has a clue how I can solve this without installing an old version of PHP, that would be great.
To get rid of the mysql deprecated warning you have to use Evo 1.0.15+ and you should change
$database_type = 'mysql';
to
$database_type = 'mysqli';
in config.inc.php
The 'only' thing that uses the old mysql_ functions is the installer then. The deprecated warnings are disabled in there for PHP 5.5.
MODx Evolution has a lot of old code in it. As you see by your warnings it is using deprecated mysql-functions. This is long known in the MODx Forums.
As for now you have two possible solutions:
Downgrade your local php version via WAMP to some (best, the same) PHP 5.4 version.
Change your PHP error-reporting level (inside the affected files or in your php.ini) to omit deprecated errors, as long as Evo has this issue.
Can check following solution
https://toster.ru/q/125593
really works !
:)

Connecting to Oracle in Codeigniter (undefined constant OCI_COMMIT_ON_SUCCESS)

im kind of a n00b to Oracle db's, but when i set my dbdriver in codeigniter to oci8, i get the following error, which is weird, providing the extension is enabled in the php.ini file.
I get the following error.
A PHP Error was encountered
Severity: Notice
Message: Use of undefined constant OCI_COMMIT_ON_SUCCESS - assumed 'OCI_COMMIT_ON_SUCCESS'
Filename: database/DB.php
Line Number: 82
You should install/enable the oci8 extension.
http://www.php.net/manual/en/book.oci8.php

Categories