Forums

The forums ran from 2008-2020 and are now closed and viewable here as an archive.

Home Forums Other web<-->database, how do you interact with to do them? Re: web<-->database, how do you interact with to do them?

#77591
Bob
Member

Lets say you have a database named testdb, with a username of admin and a password of admin1.
With the following PHP code, you can connect to the database, which is required if you want to add or delete stuff in it.


mysql_connect("localhost", "admin", "admin1") or die(mysql_error());
echo "Connection to MySQL established";
mysql_select_db("testdb") or die(mysql_error());
echo "Also connected to the testdb database";
?>

The following code will insert some stuff in the testdb database. Lets say that database has a table in it named tableone.


mysql_query("INSERT INTO tableone (city, country) VALUES('New York', 'USA' ) ") or die(mysql_error());
?>

This (city, country) code means stuff will be inserted in those columns, and the stuff will be ('New York', 'USA').

The line die(mysql_error()); means that it will the mysql error if there is any.

You can find some very handy information here: http://www.tizag.com/mysqlTutorial/