Jago6060 Posted July 22, 2009 Share Posted July 22, 2009 Just trying a simple connection for now, but when I try to view it via browser, it says that pg_connect is an undefined function. I'm using php5 <? $connection=pg_connect("host=***.***.***.*** dbname=**** user=**** password=*********************"); if($connection){ echo "Connected"; }else{ echo "Unable to connect"; } ?> Any idea why pg_connect wouldn't be recognized? Quote Link to comment https://forums.phpfreaks.com/topic/166981-solved-cant-connect-to-postgres-database-with-php/ Share on other sites More sharing options...
Maq Posted July 22, 2009 Share Posted July 22, 2009 Do you have the module loaded? You need to include the postgres extension in php.ini and restart apache. You can check with phpinfo(). Quote Link to comment https://forums.phpfreaks.com/topic/166981-solved-cant-connect-to-postgres-database-with-php/#findComment-880465 Share on other sites More sharing options...
Jago6060 Posted July 22, 2009 Author Share Posted July 22, 2009 Do you have the module loaded? You need to include the postgres extension in php.ini and restart apache. You can check with phpinfo(). Pardon the lack of knowledge...but I found this section in php.ini. Is this what I'm looking for? [PostgresSQL] ; Allow or prevent persistent links. pgsql.allow_persistent = On ; Detect broken persistent links always with pg_pconnect(). ; Auto reset feature requires a little overheads. pgsql.auto_reset_persistent = Off ; Maximum number of persistent links. -1 means no limit. pgsql.max_persistent = -1 ; Maximum number of links (persistent+non persistent). -1 means no limit. pgsql.max_links = -1 ; Ignore PostgreSQL backends Notice message or not. ; Notice message logging require a little overheads. pgsql.ignore_notice = 0 ; Log PostgreSQL backends Noitce message or not. ; Unless pgsql.ignore_notice=0, module cannot log notice message. pgsql.log_notice = 0 Quote Link to comment https://forums.phpfreaks.com/topic/166981-solved-cant-connect-to-postgres-database-with-php/#findComment-880485 Share on other sites More sharing options...
Maq Posted July 22, 2009 Share Posted July 22, 2009 Find the section called Dynamic Extensions and uncomment the line that contains "extension=php_pgsql.dll" (Windows) or "extension=php.pgsql.so" (Linux). Restart Apache and run a script that just has these lines. phpinfo(); ?> You should be able to find a list of all the extensions that you have enabled and installed. If you see postgre than you should be able to use postgre. Quote Link to comment https://forums.phpfreaks.com/topic/166981-solved-cant-connect-to-postgres-database-with-php/#findComment-880495 Share on other sites More sharing options...
Jago6060 Posted July 22, 2009 Author Share Posted July 22, 2009 Find the section called Dynamic Extensions and uncomment the line that contains "extension=php_pgsql.dll" (Windows) or "extension=php.pgsql.so" (Linux). Restart Apache and run a script that just has these lines. <?php phpinfo(); ?> You should be able to find a list of all the extensions that you have enabled and installed. If you see postgre than you should be able to use postgre. I found the Dynamic Extensions section, but there is no line that says extension=php.pgsql.so. Is it safe to just add the line or am I missing a package of some sort? Quote Link to comment https://forums.phpfreaks.com/topic/166981-solved-cant-connect-to-postgres-database-with-php/#findComment-880505 Share on other sites More sharing options...
Maq Posted July 22, 2009 Share Posted July 22, 2009 So I assume you're using Linux since you referenced the .so extension. To answer your question, yes, add that line in your php.ini. You can check to ensure you have "php.pgsql.so" in your extension directory by going to the "extension_dir" (something like that) path. If not you will have to add it, I've never installed postgres before so I'm not sure what's configured by default. Quote Link to comment https://forums.phpfreaks.com/topic/166981-solved-cant-connect-to-postgres-database-with-php/#findComment-880518 Share on other sites More sharing options...
btherl Posted July 22, 2009 Share Posted July 22, 2009 Depending on which linux distribution you are using, you can probably install a package that will do this. On my system there is a php package, a postgresql package, AND another package which makes postgresql available from php. That last package will install itself into the apache php.ini if apache is installed. If it doesn't, Maq's instructions ought to fix it. Which distribution are you using? Quote Link to comment https://forums.phpfreaks.com/topic/166981-solved-cant-connect-to-postgres-database-with-php/#findComment-880539 Share on other sites More sharing options...
Jago6060 Posted July 22, 2009 Author Share Posted July 22, 2009 Using Ubuntu Server 9.04 I added the extension=php.pgsql.so line in php.ini. No immediate change, still says pg_connect() is not a defined function. There is a s sub-section in the "Paths and Directories" section... ; Directory in which the loadable extensions (modules) reside. ; extension_dir = "./" Does this need to be uncommented? Quote Link to comment https://forums.phpfreaks.com/topic/166981-solved-cant-connect-to-postgres-database-with-php/#findComment-880550 Share on other sites More sharing options...
Maq Posted July 22, 2009 Share Posted July 22, 2009 I added the extension=php.pgsql.so line in php.ini. No immediate change, still says pg_connect() is not a defined function Did you restart apache after you made changes to php.ini? You can check to see if postgres exists by running a script with phpinfo() in it. Does this need to be uncommented? If your extensions reside in the same directory (./) as php.ini then yes. This line just specifies where your extensions exist i.e. php.pgsql.so Quote Link to comment https://forums.phpfreaks.com/topic/166981-solved-cant-connect-to-postgres-database-with-php/#findComment-880560 Share on other sites More sharing options...
Jago6060 Posted July 22, 2009 Author Share Posted July 22, 2009 I added the extension=php.pgsql.so line in php.ini. No immediate change, still says pg_connect() is not a defined function Did you restart apache after you made changes to php.ini? You can check to see if postgres exists by running a script with phpinfo() in it. Does this need to be uncommented? If your extensions reside in the same directory (./) as php.ini then yes. This line just specifies where your extensions exist i.e. php.pgsql.so Figured it out. I did apt-get install php5-pgsql and that fixed the problem. Perhaps this is the 3rd package that was mentioned? Quote Link to comment https://forums.phpfreaks.com/topic/166981-solved-cant-connect-to-postgres-database-with-php/#findComment-880562 Share on other sites More sharing options...
Maq Posted July 22, 2009 Share Posted July 22, 2009 I added the extension=php.pgsql.so line in php.ini. No immediate change, still says pg_connect() is not a defined function Did you restart apache after you made changes to php.ini? You can check to see if postgres exists by running a script with phpinfo() in it. Does this need to be uncommented? If your extensions reside in the same directory (./) as php.ini then yes. This line just specifies where your extensions exist i.e. php.pgsql.so Figured it out. I did apt-get install php5-pgsql and that fixed the problem. Perhaps this is the 3rd package that was mentioned? Nice. I was just reading a tutorial that goes that route to install the postgres package. It puts the package in your extension_dir, adds the Dynamic Extension entry in your php.ini, and handles some other dependency issues. Quote Link to comment https://forums.phpfreaks.com/topic/166981-solved-cant-connect-to-postgres-database-with-php/#findComment-880567 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.