Tuesday, May 1, 2007

Learning PHP-MySQL: Trudging Along

In my search for code I entered mysql php test on my Google search bar and the first result was PHP/MySQL Tutorial - Part 1 by freewebmasterhelp.com. Feeling lucky (pun intended) I clicked through and upon reading was convinced that a simple <?php phpinfo(); ?> was all I needed to check if MySQL was working properly. The tutorial tells me if MySQL is mentioned on the page then it has been installed. I see MySQL and MySQLi and decide to stop right there. Then I decide to start up again.
I see Part 4 - Displaying Data and decide to give their code a test drive. I get error messages th
at I do not even want to go into so I am going to install PHPMyAdmin instead.
Must...procrastinate.....longer.
PHPMyAdmin is an administrative tool that makes handling MySQL easier.

After downloading PHPMyAdmin I unzipped the contents into c:/myserver and entered http://localhost/phpMyAdmin-2.10.1-all-languages-utf-8-only/scripts/setup.php in my web browser.

Look at all these wonderful toys.

So after going through Servers and adding my own with info I found on <?php phpinfo(); ?> I went back to the drawing board and started echoing examples from the official PHP Manual. I have been able to connect to MySQL with the following code which I derived from their section on mysql_connect()
<?php
//Example 1352. mysql_connect() example
//http://us.php.net/manual/en/function.mysql-connect.php
$user = "root";
$password= "*****";
$link = mysql_connect('localhost', $user, $password);
if (!$link) {
die('Could not connect: ' . mysql_error());
}
echo 'Connected successfully';
mysql_close($link);
?>
I am able to manipulate databases using PHPMyAdmin. Unfortunately, I still can't create a database using PHP. At least I know it is possible to connect.

No comments: