PHP Database Basics (Simple)

Source: Internet
Author: User

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)

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.