in_titusville2 Posted August 22, 2010 Share Posted August 22, 2010 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"); Quote Link to comment https://forums.phpfreaks.com/topic/211448-converting-from-postgres-to-mysql-php-mysql-beginners/ Share on other sites More sharing options...
Mchl Posted August 22, 2010 Share Posted August 22, 2010 Welcome and thanks for sharing. You might be interested to learn about mysqli which is currently recommended API for connecting to MySQL from PHP. Quote Link to comment https://forums.phpfreaks.com/topic/211448-converting-from-postgres-to-mysql-php-mysql-beginners/#findComment-1102459 Share on other sites More sharing options...
premiso Posted August 22, 2010 Share Posted August 22, 2010 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)! Quote Link to comment https://forums.phpfreaks.com/topic/211448-converting-from-postgres-to-mysql-php-mysql-beginners/#findComment-1102464 Share on other sites More sharing options...
in_titusville2 Posted August 22, 2010 Author Share Posted August 22, 2010 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... Quote Link to comment https://forums.phpfreaks.com/topic/211448-converting-from-postgres-to-mysql-php-mysql-beginners/#findComment-1102465 Share on other sites More sharing options...
in_titusville2 Posted August 22, 2010 Author Share Posted August 22, 2010 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... Quote Link to comment https://forums.phpfreaks.com/topic/211448-converting-from-postgres-to-mysql-php-mysql-beginners/#findComment-1102466 Share on other sites More sharing options...
Mchl Posted August 22, 2010 Share Posted August 22, 2010 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 Quote Link to comment https://forums.phpfreaks.com/topic/211448-converting-from-postgres-to-mysql-php-mysql-beginners/#findComment-1102468 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.