Frequently used functions
$link =mysql_connect ("Database Address", "User name", "password");//LINK Database
mysql_query ("Set names file encoding name");//Set link encoding//This is a common setup method
Mysql_set_charset ("coded name")//Set link encoding
mysql_query ("Use database name")//Select database name
mysql_select_db ("database name")//Select database name
$result =mysql_query ("SQL code")//execute the SQL code if it's just an insert or something that returns TRUE or False if the select Returns a result set
mysql_error ()//Get Database execution failure information
Use the following:
if (execution result returns collection ==false)
{
echo "failure message as follows". Mysql_error ()
}else {
echo "SQL execution succeeded"
}
get Execute SQL Results
[
$result =mysql_query ("Select ...")
while ($rec =mysql_fetch_array ($result))//will fetch a row of data from the result set and assign it to rec to fetch all the results in a row
{
while ($rec =mysql_fetch_array ($result))//will fetch a row of data from the result set and assign it to rec to fetch all the results in a row
//Where array subscript is the field name (column name) of the table this is different from Java, huh?
echo "Result 1". $rec ["Column name 1"]
echo "Result 2". $rec ["Column Name 2"]
echo "Result 3". $rec ["Column name 3"]
}
]
Here is an example of a complete link to a database
$link =mysql_connect ("127.0.0.1", "root", "root");
Mysql_set_charset ("Utf-8");
mysql_select_db ("test");
mysql_query ("INSERT into User (V1,V2) values")//This will insert the data in
PHP Database Basics (Simple)