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...
What do all of you think about PostgreSQL vs. mySQL?
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.
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.
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.
//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?
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.
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:
//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();
}