Jump to content

Recommended Posts

I've used postgres and PHP for years. I have never used MySQL until yesterday. I came across the problem of converting PHP code that works with postgres to now work with MySQL. This search for knowledge wasn't easy so I am posting some simple code conversions that may help new-comers to MySQL in the future. I'm no expert at this so there may be better ways of doing this but this is a start...

 

I hope this can help someone.

 

Postgres:

$conn = pg_Connect("dbname=$database user=apache port=5432");

MySQL:

$db_connection = mysql_connect ("localhost", "", "", true);

$db_selected=mysql_select_db($database);

 

Postgres:

$result = pg_Exec($conn, "$query");

MySQL:

$result = mysql_query($query);

 

Postgres:

$id = pg_Result($results,0,"id");

MySQL:

$id = mysql_Result($results,0,"id");

Welcome and thanks for sharing.

You might be interested to learn about mysqli which is currently recommended API for connecting to MySQL from PHP.

Thanks...

 

I will look in to this. Anything to help make this easier would be a great help... For only using MySQL 1 day I have learned a lot.

 

I don't use PHP, Postgres or MySQL much (I restore classic 1960's Mustang, Cougar, Camaro and Corvette A/C systems) but it's nice to know. Thanks again...

mysqli is great. But PDO would be my preference to use over mysqli, I just love the PDO setup, nice and easy (well once you get the hang of it)!

If I use mysqli or PDO does this require any special addons or installations on the server.? I'm on a CentOS 5 server.

 

Give me something to look forward in to reasearching...

mysqli and PDO are both PHP extensions (just like mysql library you used is). They can be enabled and disabled on demand, but very often are enabled by default. The php manual has relevant instructions in each case.

 

To see what extensions you have currently enabled use phpinfo

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.