Sunday, May 13, 2012

ITC280 Update 6

What I learned on Week 6 of the ITC280 class...

1) Here are the minimum credentials necessary to connect to MySQL via PHP
The MySQL Server Name
The MySQL UserName
The MySQL UserName's password
The name of the database

2) We use variables at the top of the page to load our credentials.
$myHostName = "localhost"; //use localhost for same machine, (zephir) or name given to you by hosting company
$myUserName = "horsey01"; //your MySQL (or Zephir) username
$myPassword = "xxxxxxxxx"; //your MySQL password (the one you made up!)
$myDatabase = "horsey01"; //db name, which is the same as our username on Zephir

3) We can store a variable with our SQL data. That way we can change it quickly.
$sql = "select * from test_Customers";

4) Here are the six steps to connect to a DB from the web:
Connect to MySQL, authenticate the MySQL users


Connect to the Database, verify authorization to this resource


Select data to be retrieved via SQL statement


Retrieve data set (result)


Loop through the data, and insert it into our page


Disconnect from MySQL, and release resources


5) We can use MySQL_num_rows to see if there is data
//loop through the data
if (mysql_num_rows($result) > 0)//at least one record!
{//show results
while ($row = mysql_fetch_assoc($result))
{
print "
";
print "FirstName: " . $row['FirstName'] . "
";
print "LastName: " . $row['LastName'] . "
";
print "Email: " . $row['Email'] . "
";
print "

";
}
}else{//no records
print '
What! No customers? There must be a mistake!!
';
}

6) We can create a custom error handler:
or die(myerror(__FILE__,__LINE__,mysql_error()));

SCORES:

*Pop Quiz #8 - 7/10 (67%)
*Test #5 - 73/100 (73%)

NOTES:
We did two assignments in one week! Assignment 6 involves more on adminer while Assignment 7 is involved more on db_test.php. We already done Assignment 6 but as for Assignment 7...

Clearly, some Blue Sky Thinking involved for me because since Wednesday, we did Assignment 7, which involves on db_test.php that has to be worked on two working sites. I have the SQL and I have one onto my Zephir but as for the alternative host...Well, I kinda need some blue sky thinking right now but I have to act fast because I have until Monday to finish Assignment 7.

That is all...

2 comments:

Bill said...

Leopaul,

If you need some help setting up your alternate host for A7, let me know.

Rebecca in the lab is well versed as well.

If you need a little more time for this assignment due to having difficulty setting up the alternate host, don't worry!

This part is decidedly difficult. A6 was pretty easy, A7 can be difficult. The assignments will vary.

You're doing great! Thanks for the heads up about the blog post!!

Bill

Bill said...

Leopaul,

A7 and the extra credit, Dynamic Content both look great!

Thanks for working so hard!

Bill