PHP Introductory Learning Knowledge Point one PHP and MySQL connection and query _php Foundation

Source: Internet
Author: User
Tags php and php and mysql
One, the connection database
1, mysql_connect: Open MySQL Link

Mysql_connect (' host ', ' username ', ' password ')

2, mysql_select_db: Open a Database
mysql_select_db (' database name ', $ link identifier)//link identifier not filled out defaults to last open connection

3, mysql_query ("Set names ' GBK '") to solve the Chinese garbled problem;

mysql_query ("Set Names ' encoding (UTF8 or GBK)")//utf8 cannot have "-"

Second, query data

1, mysql_query (SQL statement, connection identifier);

$sql = "SELECT * FROM Test"
$result =mysql_query ($sql)//Connection identification Fummer considered the last open link

Get error message

$result = @mysql_query ($sql) or Die (Mysql_error ())

2, get the results of the query

A, mysql_fetch_row ($result);

$row =mysql_fetch_row ($result);
echo $row [0];

B, Mysql_fetch_array ($result);

$row =mysql_fetch_array ($result);
echo $row [0];
echo $row [' key '];


Description: Mysql_fetch_array and Mysql_fetch_row functions are basically the same, except that it can be indexed by the offset from 0, but also by domain name.
Value returns all the field values for the next row and saves them to an array, with no rows returning false.
Related Article

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.