Fatal error: Call to undefined function pg_connect - php

I am using Windows 7, php 5.3.5 and WAMP server. I have two php files: trigger.php and background.php.
I want to run background.php as a background process. I have to call this file from trigger.php. To accomplish this I used below method.
I included following code in trigger.php to make background.php to process in background.
$handle = popen('start /b C:\wamp\bin\php\php5.3.5\php.exe C:\wamp\www\email3.php','r');
in background.php I have the follwing code to connect to database.
$conn_string = "host=localhost port=5432 dbname=tagbase user=postgres password=postgres";
now, on parsing this line am getting the follwing error :
Fatal error: Call to undefined function pg_connect() in C:\wamp\www\background.php on line 3 Call Stack: 0.0002 322792 1. {main}() C:\wamp\www\background.php:0
By searching in in the internet I found some solutions, and made changes as recommended below in php.ini,
uncommented, extension=php_pdo_pgsql.dll,
uncommented, extension=php_pgsql.dll,
uncommented, extension_dir = "c:/wamp/bin/php/php5.3.5/ext/",
also I do have php_pdo_pgsql.dll and php_pgsql.dll files in c:/wamp/bin/php/php5.3.5/ext/ folder.
Any suggestions are appreciated.

Apache 2.2.X configuration
Add the next line to the Apache 2.2.x httpd.conf configuration:
LoadFile "C:/Program Files/PostgreSQL/{version}/bin/libpq.dll"
Above line must be entered before the next line.
LoadModule php5_module "c:/wamp/bin/php/php5.2.11/php5apache2_2.dll"
PHP 5.2.X Configuration
Enable the following two lines in the php.ini configuration file. By 'Enable' i mean, remove trailing ; (semicolon). By these, you un-comment the line.
extension=php_pdo_pgsql.dll
extension=php_pgsql.dll
Restart WAMP
Test by adding this in your index.php
echo extension_loaded('pgsql') ? 'yes':'no';
(source: http://www.plaatsoft.nl/wamp-postgresql-integration/)

if we install WAMP server, we will get two php.ini files.
one in C:\wamp\bin\php\php5.3.5 and another in C:\wamp\bin\apache\Apache2.2.17\bin.
if we execute a php file from browser, then php.ini file in C:\wamp\bin\apache\Apache2.2.17\bin will be referred.
if we execute a php file from command line, then php.ini file in C:\wamp\bin\php\php5.3.5 will be referred.
what ever the changes i made enable/disable the dll in PHP->PHP extensions,all the changes will be saved in
C:\wamp\bin\apache\Apache2.2.17\bin\php.ini file. but C:\wamp\bin\php\php5.3.5\php.ini file remains unchanged.
for my problem, i made the following changes
uncommented, extension=php_pdo_pgsql.dll,
uncommented, extension=php_pgsql.dll,
uncommented, extension_dir = "c:/wamp/bin/php/php5.3.5/ext/",
in C:\wamp\bin\php\php5.3.5\php.ini file. Now its working good. :)

In my case with
Apache/2.4.10
PHP Version 5.4.32
PostgeSQL 9.3
I added libpq.dll into Apache httpd.conf from PHP catalog because Apache refused to start with libpq.dll from PostgreSQL 9.3

Related

Php, "call to undefined function curl_init()" in browser BUT works fine on cmd

I have a simple test code:
<?php
var_dump(curl_init());
echo '.';
if I run it on command line (Windows 10) I get the expected result:
php.exe test.php
resource(4) of type (curl) .
very fine. But when Im running this file from browser (set to Apache rootdir).
Fatal error: Uncaught Error: Call to undefined function curl_init() in
Im speachless. For legacy reasons, this is php 7.04 (on 7.2, 7.4, 8.1 everything is fine).
The php.ini does work. Of course "extension=php_curl.dll" is enabled. When I change something, for example "max_execution_time = 300", the php_info(); also reinforcements me that these settings are taken into account.
However, the strange thing is what php_info() is saying:
cURL Sterling Hughes
nothing more for curl!
EDIT:
I tried the same with "extension=php_gd2.dll" and it does work if I remove/readd it, phpinfo shows that correctly!
This is because the php folder is not in your system PATH (not user), Apache doesn't know where to search dlls. The easiest way is adding php folder to PATH.
If you doesn't want to do that, you probably need set extension_dir to the full path of your extension folder in php.ini. for example:
extension_dir = "D:\Program Files\php-7.04-ts\ext"
cURL extension needs openssl to work. and you can also find these dlls in php folder, just copy them to Windows or system32 folder. According to RiggsFolly's comment you can copy these required dlls to Apache\bin folder.
libssl-1_1-x64.dll / libeay32.dll
libcrypto-1_1-x64.dll / ssleay32.dll
libssh2.dll

PHP Fatal error: Could not delete queued timer in Unknown on line 0

I'm getting the error when trying to access any page running on the builtin php webserver (including just a phpinfo):
Fatal error: Could not delete queued timer in Unknown on line 0
This is the command I am using to run the server
~/php-win$ wine php.exe -S localhost:8080
Here is the content of my php.ini file, which I am assuming is the cause of the error because of the Unknown on line 0 part.
Through trial and error I have discovered that if I comment out the max_input_time value then pages will load fine however the error shows up at the bottom of the page instead. See the below image:
I also had the exact same issue when attempting to set up an EasyPHP server as well (through wine also).
The only other question I could find on this error was this question, however this is happening when I run any file through the built-in webserver, including a blank file.
Also, I am using PHP 7.1.3
Edit your php.ini and put the location of extension folder , the folder named ext inside your php folder
php.ini
; Directory in which the loadable extensions (modules) reside.
; http://php.net/extension-dir
; extension_dir = "./"
; On windows:
extension_dir = "/media/viney/01D58852BCA3B9C0/UwAmp/bin/php/php-7.0.3/ext"
Then I enable a few extensions in php.ini
php.ini
extension=php_soap.dll
extension=php_sockets.dll
extension=php_sqlite3.dll
extension=php_tidy.dll
extension=php_xmlrpc.dll
extension=php_xsl.dll
Now if I run php, extenions get loaded
viney#Notebook:/media/viney/01D58852BCA3B9C0/UwAmp/bin/php/php-7.0.3$ wine php -S localhost:8080
PHP 7.0.3 Development Server started at Mon May 4 09:28:07 2020
Listening on http://localhost:8080
Document root is Z:\media\viney\01D58852BCA3B9C0\UwAmp\bin\php\php-7.0.3
Press Ctrl-C to quit.

How to install mysqli (Fatal error: Class 'mysqli' not found) NO mysqli section in phpinfo() [duplicate]

I just deployed my website to a staging environment and am getting the following error:
Fatal error: Class 'mysqli' not found in D:\ClientSites\baileyboiler.com\www\new\php\db.php on line 11
At first I assumed that MySQLI was simply not installed, but running a phpinfo() reveals the following:
To me it looks like MySQLI is installed (though I could be reading this wrong). What should I do?
Code
class DB
{
public static function GetConnection()
{
return new mysqli(DBHOST, DBUSER, DBPASSWORD, DEFAULTDATABASE);
}
}
(line 11 is the return new mysql(...);)
Update
I added extension=php_mysqli.dll to my php.ini located at /Windows/php.ini (according to phpinfo(), this is the one being loaded):
Loaded Configuration File C:\WINDOWS\php.ini
But the error persists. I know that mysqli.dll exists at C:\php\ext - because I can see the file. What now?
I got the error corrected by enabling/editing the following config in php.ini:
1st (uncomment and add config):
include_path = "C:\php\includes"
2nd (uncomment):
extension_dir = "ext"
3rd (uncomment and edit config):
extension=D:/PHP/ext/php_mysql.dll
extension=D:/PHP/ext/php_mysqli.dll
Make sure is enabled under php.ini just find php_mysqli.dll and remove semi-colon and restart apache
Christian Mark is right but I think it need:
4rd Copy php.ini to "C:\Windows". On my computer, need copy it to "C:\Windows", Because phpinfo() output "Configuration File (php.ini) Path: C:\Windows" and "Loaded Configuration File: C:\Windows\php.ini"
5rd login out Computer and login in.
Then it work for me.
If I don't do 4,5rd, It's also don't work for me, the phpinfo output include_path is not my configured. and extension_di also not. run the test also not work.

MySQLi not found error

I just deployed my website to a staging environment and am getting the following error:
Fatal error: Class 'mysqli' not found in D:\ClientSites\baileyboiler.com\www\new\php\db.php on line 11
At first I assumed that MySQLI was simply not installed, but running a phpinfo() reveals the following:
To me it looks like MySQLI is installed (though I could be reading this wrong). What should I do?
Code
class DB
{
public static function GetConnection()
{
return new mysqli(DBHOST, DBUSER, DBPASSWORD, DEFAULTDATABASE);
}
}
(line 11 is the return new mysql(...);)
Update
I added extension=php_mysqli.dll to my php.ini located at /Windows/php.ini (according to phpinfo(), this is the one being loaded):
Loaded Configuration File C:\WINDOWS\php.ini
But the error persists. I know that mysqli.dll exists at C:\php\ext - because I can see the file. What now?
I got the error corrected by enabling/editing the following config in php.ini:
1st (uncomment and add config):
include_path = "C:\php\includes"
2nd (uncomment):
extension_dir = "ext"
3rd (uncomment and edit config):
extension=D:/PHP/ext/php_mysql.dll
extension=D:/PHP/ext/php_mysqli.dll
Make sure is enabled under php.ini just find php_mysqli.dll and remove semi-colon and restart apache
Christian Mark is right but I think it need:
4rd Copy php.ini to "C:\Windows". On my computer, need copy it to "C:\Windows", Because phpinfo() output "Configuration File (php.ini) Path: C:\Windows" and "Loaded Configuration File: C:\Windows\php.ini"
5rd login out Computer and login in.
Then it work for me.
If I don't do 4,5rd, It's also don't work for me, the phpinfo output include_path is not my configured. and extension_di also not. run the test also not work.

How do I install MySQL modules within PHP?

I've updated php.ini and moved php_mysql.dll as explained in steps 6 and 8 here.
I get this error…
Fatal error: Call to undefined function mysql_connect() in C:\inetpub...
MySQL doesn't show up in my phpinfo; report.
I've updated the c:\Windows\php.ini file from
; Directory in which the loadable extensions (modules) reside.
extension_dir = "./"
to
; Directory in which the loadable extensions (modules) reside.
extension_dir = ".;c:\Windows\System32"
Result: no change.
I changed the php.ini value of extension_dir thusly:
extension_dir = "C:\Windows\System32"
Result: much more in the phpinfo; report, but MySQL still isn't working.
I copied the file libmysql.dll from folder C:\php to folders C:\Windows\System32 and C:\Windows
Result: no change.
I stopped and restarted IIS.
Result: new, different errors instead!
Warning: mysql_connect() [function.mysql-connect]: Access denied for
user '...'#'localhost' (using password: YES) in C:\inetpub\...
error in query.
Fatal error: Call to a member function RecordCount() on a non-object
in C:\inetpub\...
I found several .php files in the website where I had to set variables:
$db_user
$db_pass
Result: The site works!
As the others say these two values in php.ini are crucial.
I have the following in my php.ini: note the trailing slash - not sure if it is needed - but it does work.
extension_dir = "H:\apps\php\ext\"
extension=php_mysql.dll
Also it is worth ensuring that you only have one copy of php.ini on your machine - I've had problems with this where I've been editting a php.ini file which php isn't using and getting very frustrated until I realised.
Also if php is running as a module within apache you will need to restart the apache server to pickup the changes. Wise to do this in anycase if you're not sure.
a "php -m" from the cmd prompt will show you the modules that are loaded from the ini file.
In the php.ini file, check if the extention path configuration is valid.
You will need to enable the extension=php_mysql.dll option in the php.ini as well. Also, make sure that the file is in the extension_dir you set.
You can read more about it at:
http://us3.php.net/manual/en/install.windows.extensions.php
On a completely different note, might I suggest WampServer? It should get you up and running with a Apache/PHP/MySQL install in no time.
You could even compare the WampServer config files with your own to see where you originally went wrong.

Categories