Online Manual
Please see notice on manual index page, click here.
For support on demand visit our new support channel, TQ Support!
<< Chapter 16 - MySQL Database
Using PHP to access your MySQL databases and users
(Last modified Oct 14, 2002 )
You can use PHP to access your MySQL database and display data on your web pages. There are several PHP functions available for this process, for detailed information please refer to the PHP website or PHP documentation.
Below is a very basic example which can be extrapolated into more advanced functions:
<?php
$connection=mysql_connect("localhost", "username", "password");
$result = mysql_query("select * from table",$connection);
$array=mysql_fetch_assoc($result);
echo $array[field_name];
?>
Note: You can determine the name of your database from your domain name. If your domain name is abc.com then the name of your database is abc_com
Here is an example using a sample account. This will retreive the value of the field named "items" for the first record from the "products" table in the abc_com database. Replace the account information listed here with your own account information.
Domain name: abc.com
Database name: abc_com
Account User name: test
Account Password: test
<?php
$connection=mysql_connect("localhost", "test", "test");
$result = mysql_query("select * from products",$connection);
$array=mysql_fetch_assoc($result);
echo $array[items];
?>
Note: You do not need to substitute a host name for "localhost". The value "localhost" tells the script that the database being used resides on the same server as the script.
|