[PHP] How to Use PHP on Baidu (BAE) and Sina (SAE) Cloud platforms to connect to MySQL and return result data

Source: Internet
Author: User
Tags mysql functions php mysql

The following describes how to use Bae to connect to MySQL. The basic call is the same as the related MySQL functions of PHP:

Mysql_query-send a MySQL Query

Mysql_fetch_array-get a row from the result set as an associated array, or number array, or both

Mysql_fetch_row-retrieve a row from the result set as an enumerated Array

Mysql_fetch_assoc-get a row from the result set as the associated array

Mysql_result-get result data

Tutorial Manual: Click to View Details

<? PHP/* Bae database connected to the Wang Hai lab * // * obtain the name of the database to be connected from the platform */$ dbname = 'civsxiiejixqjrutnrme '; /* obtain the database connection parameters from the environment variables */$ host = getenv ('HTTP _ bae_env_addr_ SQL _ip '); $ Port = getenv ('HTTP _ bae_env_addr_ SQL _port '); $ user = getenv ('HTTP _ bae_env_ak '); $ Pwd = getenv ('HTTP _ bae_env_sk');/* Then call mysql_connect () connect to the server */$ link = @ mysql_connect ("{$ host }:{ $ port}", $ user, $ PWD, true); If (! $ Link) {die ("Connect server failed :". mysql_error ($ link);}/* Call mysql_select_db () immediately after successful connection to select the database to be connected */If (! Mysql_select_db ($ dbname, $ link) {die ("select database failed :". mysql_error ($ link);}/* the connection has been fully established, other standard PHP MySQL functions can be used for Database Operations */$ SQL = "select * From 'users' limit 0, 30 ;"; // $ SQL = "insert into 'users' ('name', 'email ', 'age', 'sex') values ('test01', 'test @ sina.cn ', '12', '1'); "; $ result = mysql_query (" $ SQL ") or die (" invalid query :". mysql_error (); While ($ ROW = mysql_fetch_assoc ($ result) {PR Int_r ($ row);} echo "that's all! ";?>

The following are the connection methods of SAE, many of which have been encapsulated. You can directly use SQL statements:

<? PHP $ mysql = new saemysql (); // query $ SQL = "select * From 'user' limit 10"; $ DATA = $ mysql-> getdata ($ SQL ); $ name = strip_tags ($ _ request ['name']); $ age = intval ($ _ request ['age']); // insert $ SQL = "insert into 'user' ('name', 'age', 'regtime') values ('". $ mysql-> escape ($ name ). "','". intval ($ age ). "', now ()"; $ mysql-> runsql ($ SQL); if ($ mysql-> errno ()! = 0) {die ("error:". $ mysql-> errmsg () ;}$ mysql-> closedb () ;?>

When you connect to phpadmin, if you haven't performed the operation for a long time, the page will be prompted to expire. Press Ctrl + F5.

Press F5. Sometimes some content will not be updated, and CTRL + F5 will update all content.

The specific differences are:
F5 usually only refreshes the local cache;
CTRL + F5: delete the files in the intenet Temporary Folder and download them from the server again, that is, refresh the page completely.

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.