<?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)