Getting started: combining PHP with MYSQL ., Connect to the database? Php $ dbhostlocalhost; $ dbuserroot; your mysql username $ dbpass123456; your mysql password $ dbnamedata; your mysql database name connects to the local database
, Connect to the database
$ Dbhost = localhost;
$ Dbuser = root; // your mysql User name
$ Dbpass = 123456; // your mysql password
$ Dbname = data; // your mysql database name
// Connect to the local database
$ GLOBALS ["conn"] = mysql_connect ($ dbhost, $ dbuser, $ dbpass );
// Open the database
Mysql_select_db ($ dbname, $ GLOBALS ["conn"]);
?>
2. read a field value from the database.
// Read a column of data
$ SQL = "select * from ec_admin ";
$ Result = mysql_query ($ SQL, $ GLOBALS ["conn"]);
Printf ("username: % s
", Mysql_result ($ result, 3," UserName "));
Printf ("Password: % s
", Mysql_result ($ result, 3," UserPass "));
?>
3. Insert a data entry
$ SQL = "insert into ec_admin (UserName, UserPass) values (liugongxun2, jakemary2 )";
$ Result = mysql_query ($ SQL, $ GLOBALS ["conn"]) or die (mysql_error ());
?>
4. while loop
$ SQL = "select * from ec_admin ";
$ Result = mysql_query ($ SQL, $ GLOBALS ["conn"]);
While ($ myrow = mysql_fetch_row ($ result ))
{
Printf ("username % s password
", $ Myrow [1], $ myrow [2]);
}
?>
5. do while loop
$ SQL = "select * from ec_admin ";
$ Result = mysql_query ($ SQL, $ GLOBALS ["conn"]);
If ($ myrow = mysql_fetch_array ($ result ))
{
Do
{
Printf ("username % s password
", $ Myrow [" UserName "], $ myrow [" UserPass "]);
} While ($ myrow = mysql_fetch_array ($ result ));
}
?>
6. determine whether the form is submitted.
If ($ submit)
{}
?>
Why? Php $ dbhost = localhost; $ dbuser = root; // your mysql username $ dbpass = 123456; // your mysql password $ dbname = data; // your mysql database name // connect to the local database...