Jump to content

Converting from Postgres to MySQL PHP (MySQL beginners)


in_titusville2

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");

Link to comment
Share on other sites

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...

Link to comment
Share on other sites

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

Link to comment
Share on other sites

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.