I'm testing out php 7 and have come across this error:
Fatal error: Uncaught Error: Call to undefined function odbc_connect()
From the doc page: http://php.net/manual/en/function.odbc-connect.php php 7 is not listed as supported.
Does anyone have a way around this or know when it will be supported?
Thanks#
There is written in doc: ODBC support doesn't need any extension dll. It is true in PHP 5.x, I had to remove "extension=php_odbc.dll" from ini file.
But in PHP 7 I had to put it back.
I found the file "ext/php_odbc.dll" in the new PHP 7 directory again. It works for me :).
The DOC page does list PHP 7, so just install php-odbc and you should be good to go. Currently using it myself on RedHat EL7 with Remi php7.
I ran into the same problem. However according to the link you provided PHP7 is in fact supported. So I'm not sure why you have so many comments telling you to go re-write your code.
This is what ultimately fixed the issue for me:
sudo apt-get install php-odbc
Followed by restarting Apache.
PHP 7.2.7, add extension=php_odbc.dll in php.ini file while either using database as MS Access or Sql Server
C:\xxxxxx\php\php.ini
*no semicolon before to extension=php_odbc.dll
Just enble "php_odbc.dll" extension by removing the semicolon and restart Apache.
If there is no such line in php.ini, simply create it on yourself (you will find many similar lines in php.ini) by adding: extension=php_odbc.dll and then restart Apache.
If Apache does not start or cannot load php_odbc.dll, look into to the ext-Folder of PHP, if there is such a DLL called php_odbc.dll. If there is no such DLL, Xampp/PHP7 does not support ODBC natively. In that case you should install an older Xampp Version with PHP 5.x
From php.ini file:
> ; Notes for Windows environments :
> ;
> ; - ODBC support is built in, so no dll is needed for it.
> ; - Many DLL files are located in the extensions/ (PHP 4) or ext/ (PHP 5+)
But, in PHP 7, ODBC is not by default. Explicit
extension=odbc
worked for me (new syntax recommended)
Edit:
If your architecture is x64
you must use C:\Windows\SysWOW64\odbcad32.exe
instead of C:\Windows\system32\odbcad32.exe
Here is the error message:
Redhat PHP Fatal error: Uncaught Error: Call to undefined function
odbc_connect()
On Redhat Linux 7 you run:
yum install php-odbc
You will get these packages marked in red:
Code sample to test your connection via php command line run: php [filename].php
<?php
// filename: test-connection.php by running command -> php test-connection.php
$connect = odbc_connect("Driver=FreeTDS; Server=sbase.company.ca; Port=1433; TDS_Version=8; ClientCharset=UTF-8; Database=mydbase",'company\\user', 'password');
$query = "SELECT * from mytable";
// perform the query
$result = odbc_exec($connect, $query);
// fetch the data from the database
while(odbc_fetch_row($result)){
$suid = odbc_result($result, 1);
$uid = odbc_result($result, 2);
$gid = odbc_result($result, 3);
$name = odbc_result($result, 4);
print("$name|$suid|$uid|$gid\n");
}
// close the connection
odbc_close($connect);
?>
Enjoy!
Related
I am trying to use semaphores on php but cannot get sem_get() function to work. Here is my PHP code:
<?php
$key = 123567;
$maxAcquire = 1;
$permissions = 0666;
$autoRelease = 1;
//it gives the error on the line below
$semaphore = sem_get($key, $maxAcquire, $permissions, $autoRelease);
sem_acquire($semaphore);
echo "hello world!";
sem_release($semaphore);
?>
When I try to run it with:
php semaphore.php
It prints this error:
PHP Fatal error: Uncaught Error: Call to undefined function sem_get()
in /root/semaphore.php:8
Stack trace:
#0 {main}
thrown in /root/semaphore.php on line 8
I am working on Arch Linux with PHP 7.0.3 (cli). I guess the solution is so simple but I couldn't find a way to fix it. If you could help me, I would appreciate it. Thanks.
Support for semaphores is not a standard feature of php.
It has to be activated via compiler --enable-sysvsem option when creating the php binary.
See explanation in manual: http://php.net/manual/en/sem.installation.php
Thank you all! I uncommented the line :
extension=sysvsem.so
on php.ini and it worked!
The semaphore extension is not available by default, as stated in the docs:
Support for this functions are not enabled by default. To enable System V semaphore support compile PHP with the option --enable-sysvsem . To enable the System V shared memory support compile PHP with the option --enable-sysvshm . To enable the System V messages support compile PHP with the option --enable-sysvmsg .
If you are on a hosted server, then that hosting service probably does not offer this.
Have a look at the docs. It feels like you do not have installed php with semaphores properly. Have a look at the installation instructions.
I'm testing out php 7 and have come across this error:
Fatal error: Uncaught Error: Call to undefined function odbc_connect()
From the doc page: http://php.net/manual/en/function.odbc-connect.php php 7 is not listed as supported.
Does anyone have a way around this or know when it will be supported?
Thanks#
There is written in doc: ODBC support doesn't need any extension dll. It is true in PHP 5.x, I had to remove "extension=php_odbc.dll" from ini file.
But in PHP 7 I had to put it back.
I found the file "ext/php_odbc.dll" in the new PHP 7 directory again. It works for me :).
The DOC page does list PHP 7, so just install php-odbc and you should be good to go. Currently using it myself on RedHat EL7 with Remi php7.
I ran into the same problem. However according to the link you provided PHP7 is in fact supported. So I'm not sure why you have so many comments telling you to go re-write your code.
This is what ultimately fixed the issue for me:
sudo apt-get install php-odbc
Followed by restarting Apache.
PHP 7.2.7, add extension=php_odbc.dll in php.ini file while either using database as MS Access or Sql Server
C:\xxxxxx\php\php.ini
*no semicolon before to extension=php_odbc.dll
Just enble "php_odbc.dll" extension by removing the semicolon and restart Apache.
If there is no such line in php.ini, simply create it on yourself (you will find many similar lines in php.ini) by adding: extension=php_odbc.dll and then restart Apache.
If Apache does not start or cannot load php_odbc.dll, look into to the ext-Folder of PHP, if there is such a DLL called php_odbc.dll. If there is no such DLL, Xampp/PHP7 does not support ODBC natively. In that case you should install an older Xampp Version with PHP 5.x
From php.ini file:
> ; Notes for Windows environments :
> ;
> ; - ODBC support is built in, so no dll is needed for it.
> ; - Many DLL files are located in the extensions/ (PHP 4) or ext/ (PHP 5+)
But, in PHP 7, ODBC is not by default. Explicit
extension=odbc
worked for me (new syntax recommended)
Edit:
If your architecture is x64
you must use C:\Windows\SysWOW64\odbcad32.exe
instead of C:\Windows\system32\odbcad32.exe
Here is the error message:
Redhat PHP Fatal error: Uncaught Error: Call to undefined function
odbc_connect()
On Redhat Linux 7 you run:
yum install php-odbc
You will get these packages marked in red:
Code sample to test your connection via php command line run: php [filename].php
<?php
// filename: test-connection.php by running command -> php test-connection.php
$connect = odbc_connect("Driver=FreeTDS; Server=sbase.company.ca; Port=1433; TDS_Version=8; ClientCharset=UTF-8; Database=mydbase",'company\\user', 'password');
$query = "SELECT * from mytable";
// perform the query
$result = odbc_exec($connect, $query);
// fetch the data from the database
while(odbc_fetch_row($result)){
$suid = odbc_result($result, 1);
$uid = odbc_result($result, 2);
$gid = odbc_result($result, 3);
$name = odbc_result($result, 4);
print("$name|$suid|$uid|$gid\n");
}
// close the connection
odbc_close($connect);
?>
Enjoy!
We have a Windows 2008 server, this morning when we came to the office, we saw that mysql is not working
We are getting this error for a simple connect function
Fatal error: Call to undefined function mysql_connect()
but the strange thing is that mysql extensions are enabled in php.ini file.
extension=php_mysql.dll
extension=php_mysqli.dll
extension=php_pdo_mysql.dll
According to phpinfo() , php using the ini file in C:\PHP and the DLL files exist in the ext folder.
I cannot find a way to solve or at least to find out what is causing this.
I would be grateful if someone could give me some advice
Thanks in advance
for debugging purposes try
if ( !function_exists('mysql_connect') ) {
echo '<pre>mysql extension loaded: ', extension_loaded('mysql') ? 'yes':'no', "\r\n";
$cf = get_cfg_var('cfg_file_path');
echo 'ini file: ', $cf, "\r\n";
if ( !$cf || !file_exists($cf) ) {
echo "no config file\r\n";
}
else {
echo "mysql config options:\r\n";
$mc = array_filter( file($cf), function($e) { return false!==stripos($e, 'mysql') && false!==stripos($e, 'extension'); });
echo join("", $mc);
}
die('no function mysql_connect</pre>');
}
the output should be something like
<pre>mysql extension loaded: no
ini file: C:\Develop\php\php.ini
mysql config options:
;extension=php_mysql.dll
;extension=php_mysqli.dll
extension=php_pdo_mysql.dll
no function mysql_connect</pre>
which indicates that the line extension=php_mysql.dll has been commented out (in my php.ini).
In case this script shows that the php_mysql.dll indeed should have been loaded try to increase the log level of both php and your webserver and check the log file. Maybe windows couldn't load the dll because it depends on another dll which isn't present (in the correct version) anymore. E.g. the php_mysql.dll in "my" ext directory depends on MSVCR110.DLL which is present because I have Visual Studio installed, otherwise installing the Visual Studio 2012 redistributables would be required. Tools like Dependency Walker can show you which dlls are required to run an application and/or dll.
Or it could be that the php_mysql.dll implements a different API version than your php core. E.g. if you have PHP 5.4 installed but the php_mysql.dll is for php 5.1 you will see an API magic key error in the log file.
Restart Your WAMP Or XAMPP Server. You can check with Contral Panel of XAMPP Or WAMP
This question already has answers here:
Fatal error: Uncaught Error: Call to undefined function mysql_connect()
(9 answers)
Closed 3 months ago.
I have set up PHP, MySQL, and Apache. localhost() for PHP and it is working well. But after I downloaded MySQL, it reports:
Fatal error: Call to undefined function mysql_connect()
How can I fix this?
You upgraded to PHP 7, and now mysql_connect is deprecated. Check yours with:
php -version
Change it to mysqli_connect as in:
$host = "127.0.0.1";
$username = "root";
$pass = "foobar";
$con = mysqli_connect($host, $username, $pass, "your_database");
If you're upgrading legacy PHP, now you're faced with the task of upgrading all your mysql_* functions with mysqli_* functions.
If you get this error after upgrading to PHP 7.0, then you are using deprecated libraries.
mysql_connect — Open a connection to a MySQL Server Warning This
extension was deprecated in PHP 5.5.0, and it was removed in PHP
7.0.0. Instead, the MySQLi or PDO_MySQL extension should be used.
More here: http://php.net/manual/en/function.mysql-connect.php
Open your terminal and run bellow command.
sudo apt-get install mysql-server
If you are running PHP you will also need to install the php module for mysql 5:
sudo apt-get install php5-mysql
Verify that your installation of PHP has been compiled with mysql support. Create a test web page containing <?php phpinfo(); exit(); ?> and load it in your browser. Search the page for MySQL. If you don't see it, you need to recompile PHP with MySQL support, or reinstall a PHP package that has it built-in
PHP.INI
Check if you forgot to enable the options below(loads the modules for mysql among others):
; Directory in which the loadable extensions (modules) reside.
; http://php.net/extension-dir
; extension_dir = "./"
; On windows:
extension_dir = "ext"
Use.
<?php $con = mysqli_connect('localhost', 'username', 'password', 'database'); ?>
In PHP 7.
You probably have PHP 7 in XAMPP. You now have two option: MySQLi and PDO.
For CPanel users, if you see this error and you already have PHP 5.x selected for the site, there might be a CPanel update that disabled mysql and mysqli PHP extensions.
To check and enable the extensions:
Go to Select PHP Version in CPanel
Make sure you have PHP 5.x selected
Make sure mysql and mysqli PHP extensions are checked
This error is coming only for your PHP version v7.0.
you can avoid these using PHP v5.0
else
use it
mysqli_connect("localhost","root","")
i made only mysqli from mysql
A solution could be to use adapter functions like these to start using mysqli instead of mysql over your entire application:
if (!function_exists('mysql_connect')) {
function mysql_connect($host = '', $user = '', $password = '', $database = '', $port = 0, $socket = '') {
return mysqli_connect($host, $user, $password, $database, $port, $socket);
}
}
if (!function_exists('mysql_select_db')) {
function mysql_select_db($link, $dbname) {
mysqli_select_db($link, $dbname);
}
}
I had this same problem on RHEL6. It turns out that the mysql.ini file in /etc/php.d only had a module name but needed a full path name. On my RHEL6 system the entry that works is:
; Enable mysql extension module
extension=/usr/lib64/php/modules/mysql.so
After modifying the file, I restarted apache and everything worked.
My solution is here (I needed just to remove the last slash (NB: backward slashes) from PHPIniDir 'c:\PHP\'): Fatal error: Call to undefined function mysql_connect() cannot solve
Am using windows 8 n this issue got resolved by changing the environment variables
follow these steps:
Open my computer properties->advanced system settings->Environment variables.
Under 'system variables', select 'path' and click on 'edit'
In 'variable value', add 'C:\php;' OR the path where php installed.
click OK and apply the settings and restart the system.
It should work.
Here is a quick fix:
All the pros will probably hate me for this answer. But I got the same error on a server: Fatal error: Uncaught Error: Call to undefined function mysql_connect() that was using PHP 7. Did not have time to rewrite all the mysql code so a quick, temporary fix if anyone needs it is in CPANEL to look for PHP Configuration and change the version for that account to something like PHP 5.4 instead of PHP 7. Then the code worked fine without the above error.
If you are using Windows10, PHP 7.2 and try to connect to mysql.
If this error occurred
Uncaught Error: Call to undefined function mysqli() in
The do the following steps to get it correct.
Go to the PHP installation folder,
CHeck for php.ini file, (Only dev, prod file is there, then one of the file as php.ini file)
Look for "extension=mysqli" and remove the ";" before it.
Look for "extension_dir" and mentioned the path of "ext" directory.
Restart the application.
Hope this helps to someone.
Check if mysqli module is installed for your PHP version
$ ls /etc/php/7.0/mods-available/mysql*
/etc/php/7.0/mods-available/mysqli.ini /etc/php/7.0/mods-available/mysqlnd.ini
Enable the module
$ sudo phpenmod mysqli
This Code Can Help You
<?php
$servername = "localhost";
$username = "root";
$password = "";
$con = new mysqli($servername, $username, $password);
?>
But Change The "servername","username" and "password"
The problem shows up when you're using mysql_connect in your code lines so just add it as in mysqli_connect and it will solve the problem.
You also have to then use mysqli throughout your code lines or the problem would surface again.
The example mysql_select_db will then be mysqli_select_db for selecting Database.
I've a development computer, which runs under windows.
For a project, I've to make a php website which has to connect to an Ingres database server.
So I installed wamp, I installed ingres(server and client, on my local machine).
I added the library that I found on their site(php_ingres.dll) in the C:\wamp\bin\php\php5.3.5\ext folder, and I added a line "extension=php_ingres.dll" in the configuration file.
I shutdown wamp and restarted it, and I restarted the server, I see now a check mark in the wamp menu, indicating that php_ingres is now activated. But when I go to the welcome page of the server, I don't see this extension as loaded. If I go on the php info page, I don't see any Ingres entry in the Configure Command.
I just can't found any post/tutorial/... which indicating how to do this operation, so any help would be appreciated!
Thank you!
Edit: I made a small test to see if I can connect to an Ingres database:
<?php
$link = ingres_connect("localhost", "demodbtest", "demodbtest") or die("Connexion impossible");
echo "Connexion réussie";
$result = ingres_query($link,"select * from airline");
while ($row = ingres_fetch_array($result)) {
echo $row["al_iatacode"]; // utilisation du tableau associatif
echo $row["al_name"];
echo $row["al_ccode"]; // utilisation du tableau à indices numériques
echo "</br>";
}
ingres_close($link);
?>
And I get this error:
( ! ) Fatal error: Call to undefined function ingres_connect() in
C:\wamp\www\tests\index.php on line 2
Some information on my installation:
I've a windows 7 pro 32bits
Wampserver 2.1 ( http://sourceforge.net/projects/wampserver/files/WampServer%202/WampServer%202.1/WampServer2.1e-x32.exe/download )
Apache 2.2.17
PHP 5.3.5
Ingres 10.1.0 Community edition( downloaded here: http://esd.ingres.com/product/Community_Projects/Ingres_Database/Windows_32-Bit/Ingres_10.1_Build_121/ingres-10.1.0-121-gpl-win-x86-NoDoc.zip/http )
PHP drivers downloaded here: http://esd.ingres.com/product/drivers/PHP/Windows_32-Bit/PHP_Driver
To practically test if the extension was loaded you can as well call one of it's functions. If the extension was loaded, you should not get a fatal error for a missing function. That's perhaps one of the quickest checks.
Another check is to make use of extension_loaded *PHP Manual** which will give you a list of all loaded extensions. See the PHP Manual link above for more info.
The configure line
The configure line will not show the ingres extension because it has not been compiled in. That's perfectly alright because you load it as an extension (.dll) so it's not part of php.exe. This is why you don't see it in the configure line.
Locating ingres on the phpinfo() page.
On the phpinfo()-page use the search function inside your browser (often CTRL+F) and try to locate the word ingres. You should locate a section that displays the extensions default settings if it has been loaded.
The following is an example screenshot for the xdebug extension. This might look similar for ingres:
Image from: Launching xdebug in Eclipse stuck at 57% - How to trouble-shoot?
Double check your extension_dir setting as well as the actual php.ini file being used. Calling php.exe -i from the command line might not give the same output if executing phpinfo() in a script via Apache (or IIS). In fact http://www.wampserver.com/en/faq.php says there are 3 potential php.ini scripts.
The problem is that I wasn't having the ingres client installed locally, so it appears that this lib cannot works without it