AMFPHP video tutorial : Creating and connecting to a MySQL database
![]() |
Using AMFPHP to connect to a MySQL database Most of this tutorial is concerned with phpMyAdmin to create a database, table and user. Then we’ll write a PHP service that will connect and read/write data to the table we created. You can see an example of what we’ll create in the Flex app below |
One thing that I meant to cover but spaced was creating a dbConnection.php file that holds your mysql_connect statements. Instead of leaving those statements in the constructor like I did here:
function Blogroll() { // this is the constructor for the 'Blogroll' class
$mysql = mysql_connect( "localhost", "myUsername", "myPassword" );
mysql_select_db( "myDatabase" );
}
You can put that statement in an external file, I call mine dbConnection.php. That way you can refer to that file in all your services and if you need to update your connection statement you’ll only need to access one file. Plus, presumably, it’s more secure.
So in the end your constructor would look like this:
function Blogroll() {
include("dbConnection.php");
}
And your connection file would look like this:
<?php $mysql = mysql_connect( "localhost", "myUsername", "myPassword" ); mysql_select_db( "myDatabase" ); ?>
Please comment below if you have any input on how this video tutorial could be better. I’ll re-record this tutorial when I feel that I’ve gotten enough feedback to make some quality improvements.
| view source |








