How [PHP] uses PHP to connect to MySQL and return result data on the cloud platform of Baidu (BAE) and Sina (SAE)

Source: Internet
Author: User

<?PHP$dbname= ' VNOTXPFWOXZUBLTRQCCG ';$host=getenv(' Http_bae_env_addr_sql_ip ');$port=getenv(' Http_bae_env_addr_sql_port ');$user= ' 8003465908be42b9815523661dfedb4e ';$pwd= ' a25c944101634f98853b8a4ce49e9096 ';/*then call mysql_connect () to connect to the server*//*to avoid an unexpected program interruption due to a MySQL database connection failure, this is done by adding @ before the mysql_connect () function to suppress the error message and ensure that the program continues to run*//*for a detailed introduction to the mysql_connect () function, see http://php.net/manual/zh/function.mysql-connect.php*/$link= @mysql_connect("{$host}:{$port}",$user,$pwd,true);if(!$link) {     die("Connect Server Failed:".)Mysql_error());}/*call mysql_select_db () immediately after the connection is successful select the database you want to connect to*/if(!mysql_select_db($dbname,$link)) {     die("Select Database Failed:".)Mysql_error($link));}/*Now that the connection is fully established, the current database can be manipulated accordingly.*/$sql= "SELECT * from ' weather ' LIMIT 0, 3;";$result=mysql_query($sql) or die("Invalid query:".)Mysql_error()); while($row=Mysql_fetch_assoc($result)) {    Print_r($row);}/*explicitly close the connection, not required*/Mysql_close($link);?>

PHP connection MySQL<?PHP/*Replace with your own database name*/$dbname= ' Eizrxdyagzrycjutrljt ';/*fill in the database connection information*/$host= ' sqld.duapp.com ';$port= 4050;$user= ' <User_AK> ';//User AK$pwd= ' <User_SK> ';//User SK /*The above information can be found on the database details page*//*then call mysql_connect () to connect to the server*//*to avoid an unexpected program interruption due to a MySQL database connection failure, this is done by adding @ before the mysql_connect () function to suppress the error message and ensure that the program continues to run*//*for a detailed introduction to the mysql_connect () function, see http://php.net/manual/zh/function.mysql-connect.php*/$link= @mysql_connect("{$host}:{$port}",$user,$pwd,true);if(!$link) {     die("Connect Server Failed:".)Mysql_error());}/*call mysql_select_db () immediately after the connection is successful select the database you want to connect to*/if(!mysql_select_db($dbname,$link)) {     die("Select Database Failed:".)Mysql_error($link));}/*Now that the connection is fully established, the current database can be manipulated accordingly.*///To Create a database table$sql= "CREATE table if not exists test_mysql (ID int primary key auto_increment, no int, name varchar (1 024), Key Idx_no (NO))";$ret=mysql_query($sql,$link);if($ret===false) {     die("Create Table Failed:".)Mysql_error($link));} Else {    Echo"Create Table succeed<br/>";} /*explicitly close the connection, not required*/Mysql_close($link);?>

How [PHP] uses PHP to connect to MySQL and return result data on the cloud platform of Baidu (BAE) and Sina (SAE)

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.