Quck question about PostgreSQL vs mySQL

Questions about the MySQL, PostgreSQL, and most other databases, as well as using it with PHP can be asked here.

Moderator: General Moderators

Post Reply
Pavilion
Forum Contributor
Posts: 301
Joined: Thu Feb 23, 2012 6:51 am

Quck question about PostgreSQL vs mySQL

Post 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
User avatar
pickle
Briney Mod
Posts: 6445
Joined: Mon Jan 19, 2004 6:11 pm
Location: 53.01N x 112.48W
Contact:

Re: Quck question about PostgreSQL vs mySQL

Post 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.
Real programmers don't comment their code. If it was hard to write, it should be hard to understand.
Pavilion
Forum Contributor
Posts: 301
Joined: Thu Feb 23, 2012 6:51 am

Re: Quck question about PostgreSQL vs mySQL

Post 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
User avatar
pickle
Briney Mod
Posts: 6445
Joined: Mon Jan 19, 2004 6:11 pm
Location: 53.01N x 112.48W
Contact:

Re: Quck question about PostgreSQL vs mySQL

Post 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.
Real programmers don't comment their code. If it was hard to write, it should be hard to understand.
Pavilion
Forum Contributor
Posts: 301
Joined: Thu Feb 23, 2012 6:51 am

Re: Quck question about PostgreSQL vs mySQL

Post 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
Pavilion
Forum Contributor
Posts: 301
Joined: Thu Feb 23, 2012 6:51 am

Re: Quck question about PostgreSQL vs mySQL

Post 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
Post Reply