January 13, 2007
<?php
mysql_connect(“localhost”, “admin”, “1admin”) or die(mysql_error());
echo “Connected to MySQL<br />”;
?>
If you load the above PHP script to your webserver and everything works properly, then you should see “Connected to MySQL” displayed when you view the .php page.
The mysql_connect function takes three arguments. Server, username, and password. In our example above these arguments were:
- Server – localhost
- Username – admin
- Password – admin
Now let’s say you want to access a specific database you can use:
After establishing a MySQL connection with the code above, you then need to choose which database you will be using with this connection. This is done with the mysql_select_db function.
<?php
mysql_connect(“localhost”, “admin”, “1admin”) or die(mysql_error());
echo “Connected to MySQL<br />”;
mysql_select_db(“test”) or die(mysql_error());
echo “Connected to Database”;
?>
the display message should be:
Connected to MySQL
Connected to Database
this is a quick little tutorial on how to conect to a MySql databse, the next tutorila will elaborate on how to create tables in that database and all the diffrent operations that you can perform.
Leave a Comment » |
IT and Programming |
Permalink
Posted by michaeljj
December 20, 2006
If you are into IT or into web development, there are plenty of resources out there for you to learn and get the best out of your web development experience. I found a new software that lets you run Apache,MySql ,PHP and Perl all in one package. You can download the software and put it on your computer just as if you were downloading any messenger programs out there, yes! it’s that easy. The good part about the software is that it runs both on Windows and Linux and you also don’t even have to be online to write your codes and test it on your server.
Here is how it works:
Go to —>> http://www.apachefriends.org/en/xampp.html
1- Download the EXE (7-zip) [MD5] for faster download and to save you instalations pain!
2- Instalation

3-After the installation is complete, you will find XAMPP under Start / Programs / XAMPP. You can use the XAMPP Control Panel to start/stop all server and also install/uninstall services.

4- Test: After Apache starts, open the URL http://localhost or http://127.0.0.1 and examine all of the XAMPP examples and tools.
if you get apage similar to this you are into business!

remember to access the XAMPP main page you can also type the IP of the localhost which is bye default 127.0.0.1 and that should take you to xampp.
Next week i’ll put a tutorial on how to upload files to your html folder and have a local website running on your computer. I’ll also put instructions on how to access your website outside of your network. So come back for some more free knowledge.
Leave a Comment » |
IT and Programming |
Permalink
Posted by michaeljj