Page 1 of 1

Quck question about PostgreSQL vs mySQL

Posted: Mon Jul 23, 2012 5:20 pm
by Pavilion
Hello Folks:

I've recently started up a new hosting account for my revised business website. The new host provides both mySQL and PostgreSQL. I've worked with mySQL for years. But a VERY QUICK review of PostgreSQLtells me it may be worth my time. So...
  1. What do all of you think about PostgreSQL vs. mySQL?
  2. Does PostgreSQL work with PDO applications. Celauran taught me the importance of PDO sometime back. If I start using Postgre, I want to make sure it's compatible with PDO.
Thanks in advance - Pavilion

Re: Quck question about PostgreSQL vs mySQL

Posted: Tue Jul 24, 2012 10:58 am
by pickle
PDO interacts with PostgeSQL just as well as MySQL as far as I know. Unless you're doing fancy stuff with your database, or it's huge, you're best to stick with MySQL since you're familiar with it.

Re: Quck question about PostgreSQL vs mySQL

Posted: Wed Jul 25, 2012 10:44 am
by Pavilion
pickle wrote:PDO interacts with PostgeSQL just as well as MySQL as far as I know. Unless you're doing fancy stuff with your database, or it's huge, you're best to stick with MySQL since you're familiar with it.
Hello Pickle:

Thanks for jumping in here. I do understand your advice to stick with something you know. But... well I'm familiar with MS SQL as well. For now... I'd like to play with PostgreSQL and figure out if I like it. Right now I'm trying to set up a PDO connection and failing. Following is my code.

Code: Select all

//Define Database
$hostname = '00.00.00.000';
$dbname= 'my_databases_name';
$username = 'my_user_name';
$password = 'my_password';


// Create PDO link to the database with the following "try" block
try 
{
$link = // Database link
new PDO("host=$hostname;dbname=$dbname", $username, $password);
echo "found databases";

}
	// This block throws an error message if there is no connection. PDO uses "exceoptions" to handle errors.
	catch(PDOException $e) {
	echo "There is an error somewhere. I have no idea where, but there is an error.";

}
I'm getting the error message as a return.

PDO is new to me and I'm trying to use the same format I used in setting up mySQL database connection, but this one is not working. Any ideas what I'm doing wrong?

Thanks Much - Pavilion

Re: Quck question about PostgreSQL vs mySQL

Posted: Wed Jul 25, 2012 10:47 am
by pickle
echo $e->getMessage(). Exceptions are useful for more than just stopping application flow, they usually have useful information about why the exception was generated.

Re: Quck question about PostgreSQL vs mySQL

Posted: Wed Jul 25, 2012 11:05 am
by Pavilion
pickle wrote:echo $e->getMessage(). Exceptions are useful for more than just stopping application flow, they usually have useful information about why the exception was generated.
OK - did as you requested and got the following:
SQLSTATE[08006] [7] FATAL: no pg_hba.conf entry for host "00.00.00.000", user "my_user", database "my_database ", SSL on FATAL: no pg_hba.conf entry for host "00.00.00.00", user "my_user", database "my_database", SSL off
After some research my script changed to the following:

Code: Select all

//Define Database
$hostname = '00.00.00.000';
$dbname= 'my_database';
$username = 'my_user';
$password = 'my_password';


// Create PDO link to the database with the following "try" block
try 
{
$link = // Database link
new PDO("pgsql:host=$hostname;port=5432;dbname=$dbname", $username, $password);
echo "found databases";

}
	// This block throws an error message if there is no connection. PDO uses "exceoptions" to handle errors.
	catch(PDOException $e) {
	echo "There is an error somewhere. I have no idea where, but there is an error.";
	
	// The following echo will return php generated message. Use for stepping through an error.
	echo $e->getMessage();
}


Thanks again for your help.

Pavilion

Re: Quck question about PostgreSQL vs mySQL

Posted: Wed Jul 25, 2012 11:38 am
by Pavilion
Called my hosting service and all I had to do is change $hostname from "00.00.00.00" to 'localhost'

Problem solved. I look forward to becoming acquainted with PostgreSQL and figuring out if I like it more than mySQL.

Pavilion