I'm trying to connect to another database within a wordpress plugin. Inside the main php file, I tried to call 'pg_connect($con_string);' but I now realize that this function is undefined. Is there a library that I need to include somewhere in the directory? Thanks.
This function is in the php-pgsql package or module. Not sure what OS you are on, but on some Linux distributions the package has version-specific naming like php5-pgsql or php7-pgsql so you might need to install the version specific to whatever PHP version you're using. You can use phpinfo() to output information that will help you troubleshooot what is going on, including versions and what packages are enabled.
The package may need to be installed, or it may be installed but disabled. It is enabled by default in PHP >= 5.3.x. If you're finding it is not included by default, you likely either have a very old version of PHP, or one that is custom-configured not to have this package enabled.
If the issue is enabling it, look in the configuration files. On some systems there is a file installed in /etc/php.d/ like 20-pgsql.ini with a line that will enable the extension. In other systems it is in php.ini which is usually somewhere in the /etc directory. Search these files for a line containing the text pgsql and make sure it is enabled. Then restart the web server (or PHP-FPM if you are using that.)
Hopefully this will address the issue.
If you need further help, the official PostgreSQL documentation is a good resource:
https://www.tutorialspoint.com/postgresql/postgresql_php.htm
And beyond that I would recommend a web search including your specific distribution and possibly PHP version, as this will return information with the correct configuration file locations and options.
Related
this is not a bug in my program but a general doubt. I've heard and read that in Windows people uncomment extension names in PHP.ini to enable them. Does this works in Ubuntu too?
Actually I've tried it in my Ubuntu and it didn't work, just want to be sure it doesn't works like this in Ubuntu or it was my fault somewhere (which doesn't matters now ).
In my case I didn't even touched the ini file but just recompiled the php from source with passing extension arguments. Why didn't I have to enable them?
Tried searching SO but didn't find any questions related to this.
With Windows, pretty much all the extensions are already compiled as DLLs. So when you uncomment the line in the ini file and restart the service, it simply loads the file.
When you compile from source in Linux, you aren't building all the extensions by default. You usually have to explicitly specify which extensions you want to enable and they are compiled along with PHP. So the extension has to be compiled successfully and be accessible to be used. The ini file is simply the instruction of whether or not to TRY loading that extension when PHP starts.
Also, there are some basic extensions that are part of the typical PHP build / configure / make process. You can consult the docs to figure out which ones are default but a good practice is to explicitly enable those that you want.
Don't build EVERY extension if you don't need them though. The more extensions that get loaded, the more memory that PHP needs/uses when starting up.
the simple answer is yes it works but if only the extension is in your ubuntu.
I'm having trouble understanding these ;extension=xxx.dll files in php.ini
Is there any document I can refer to which explains these extensions in detail?
The .dll files are for PHP extensions. You can read about all of them here: http://php.net/manual/en/install.windows.extensions.php
PHP extensions give you extra PHP functionality. They are basically function libraries that add features like MySQL functions, LDAP functions, and even Java functions.
To activate the extensions provided by the default PHP install, simply uncomment the ;extension=xxx.dll line (remove the semicolon) so that it just looks like extension=xxx.dll.
However, not all extensions are bundled with PHP. For example, the PECL extensions, including APC, have to be installed externally. Instructions for installing PECL can be found here: http://www.php.net/manual/en/install.pecl.php
"Extension Writing Part I: Introduction to PHP and Zend"
You only need to worry about those if you're running on a Windows server - since they appear to be commented out (; at the start of the line) I would assume you're on a Linux server?
In any case, you should be able to look up each extension individually on Google.
I am using a Windows XP Home Edition. I need to install a few extensions to PHP -- memcache, APC, .etc. And I would very much like to use PECL to make this happen. The problem is PECL takes it for granted that I will have certain programs on my computer. On another post, I read, for instance, that you need to have Microsoft Visual Studio C++ installed on your machine. However, the new version of Visual Studio, which I downloaded, does not have msdev.exe and instead uses vcbuild.exe, which has a completely different api and fails to compile the .dsp files that come with these modules.
So I tried to find a script that would upgrade the dsp to work with vcbuild.exe...and it turns out vcbuild.exe can do that, but of course that didn't pan out.
Another thing I tried was to find a make script for Windows (nmake2make). But there was no make file in the module's root folder.
I tried also downloading Cygwin and MinGW in hopes of finding a build script that would work as simply as in *nix operating systems, but to no avail.
How else do I use install PHP extensions on a Windows machine? Can anyone help me out of this predicament?
For all peoples coming here to download the dll extension files.
This is the link to the PHP extension download link http://windows.php.net/download/
And this is a list of PHP extensions to download: http://pecl.php.net/package-search.php
For core extensions, or if you cant find any on pecl.php.net, download PHP from a zip http://windows.php.net/download/ and look inside of /ext and copy them to your local php /ext folder.
The only way I can think of is: manually. Yeah, I know, but this is pretty easy comparatively.
If you have the compiler, then you can at least compile an extension if you have the source. Otherwise you're stuck with trying to locate a binary distribution (like me).
Here's what you do, from what I understand:
Put the extension library folder under PHP's install path. On my computer this is C:\xampp\php\ext. Search in your PHP.ini for "extension_dir" to find what yours is.
Edit php.ini to load the extension.
Find ; Dynamic Extensions ;.
Add line extension=my_lib.dll
This should do it. Otherwise you should probably search for an in-depth guide on manual installation.
For memcache you will need the memcache server located here -> http://code.jellycan.com/memcached/ and download the win32 binary
Never used APC :P I use eAccelerator0953_5.2.6 to cache the code
I need to enable the mcrypt functions on my website, except I'm on a shared host (running linux) and obviously don't have access to the php.ini file. There does seem to be options for installing PEAR modules but a search told me mcrypt wasn't available. Is there any way I can do this, short of begging technical support to help me?
Update: Looking around a bit more, it looks like I might be able to use the dl() function to dynamically load a library at run time. Since I'm only using the mcrypt functions in one spot, I could probably get away with doing this since the performance hit (I assume there is a hit) should be minimal. The only problem now is how to get the libmcrypt.so file?
Another update: I've downloaded the libmcrypt.tar.bz2 file from Sourceforge and run ./configure, make, and then copied the libmcrypt.so.4.4.8 file into my home directory (as libmcrypt.so), but now I can't find where to put it so that the dl() function will find it.
The MCrypt Sourceforge page should have it
http://mcrypt.sourceforge.net/
To compile it just:
wget http://superb-east.dl.sourceforge.net/sourceforge/mcrypt/libmcrypt-2.5.8.tar.gz
tar -xzvf libmcrypt-2.5.8.tar.gz
cd libmcrypt-2.5.8
./configure
make
sudo make install
EDIT:
Can you reference it with a direct path?
What have you tried?
Edit2: It seems that you can only load moduals from the extensions directory set in the php.ini and you cannot override extensions_dir with ini_set so you will either have to convince your host to install it or if they allow you to have your own php.ini (many do usually in [username]/php.ini) then you could set the extensions_dir in there and load the modual with that.
Really the best way is to tell your ISP to include mcrypt support. Even if you bundle your own PHP extension and load it with dl(), there is no guarantee it is going to work after a PHP upgrade, as PHP is sometimes very version-number picky.
dl() will not help you either, since it only loads libraries from certain paths, and those paths are usually only writable by the system administrators for security reasons.
I very much doubt that there is a way to use binary libraries without the consent of the hoster.
PHP in versions before 5.2.5 allowed you to use a path in the dl() function so that you could easily load libraries in a shared environment.
This changed for 'security' reasons with 5.2.5 and as far as I am aware your only option is to get your system administrator to add the module to the extensions_dir.
This issue is described at bugs.PHP.net
I need to install or use php on a windows 2003 server that already has php 5.2.0.0 installed due (I think) to setting up symantec backup exec. I don't want to interfere with backup exec's php.ini settings - and would rather be able to control my own configuration of php.
searching for php shows that php.exe and other php files are currently installed in
c:\program files\symantec\backup exec\
I'm almost certain that installing the current version of php 5.2.8 to c:\php would be disastrous or calamitous in some way.
There is no PHPRC entry in the server properties > environment variables and I'm pretty sure that the php.exe location is not included in the PATH variable. ...unless the actuall install location is different from the c:\program files\symantec\backup exec\ dir.
Any suggestions on how to proceed?
I'm almost certain that installing the current version of php 5.2.8 to c:\php would be disastrous or calamitous in some way.
What makes you say that :) I've run separate PHP versions on the same machine side by side and not run into bother.
AFAIK the Symantec install should not conflict with your own installation, nor should the separate php.ini files conflict with each other.
[Response to comment]
First thing to note is that I have no experience of Backup Exec or what it uses PHP for. I'm guessing it uses it for its own internal stuff and doesn't spread itself over the OS. Test this by searching for php.ini and php DLLs on the file system. I'm betting it's all quite self contained. PHP searches for the config file as noted here: PHP Site . As you note, BE hasn't set the PHPRC variable. Check it hasn't used those Registry entries either. On a different tack, has BE installed an admin site already on IIS? If so, check the IIS Web Service Extensions to make sure it hasn't already registered the PHP ISAPI dll or PHP CGI exe. IF not, I think you should be okay for your new install.
To be on the safe side, do a manual PHP install as illustrated here: PHP Site. That way, you know exactly what you have installed, and can easily remove the files again if they cause a problem. I can't imagine a problem here that would require you to reinstall BE.