Recently in the public development, the use of Sina's servers, as well as the database provided by Sina
The databases provided by Sina can be manipulated using the "constants" they provide:
If the user wants the specific value of these constants, you can add a php file on the Sina server, you can use the following code to see the specific values.
However, it is not necessary to use constants that are safer and more reliable because the specific values may change.
<? PHP Header ("Content-type:text/html;charset=utf-8"echo "username:".) Sae_mysql_user. " <br> "; Echo "Password:". Sae_mysql_pass. ' <br> '; Echo "Main Library domain name:". Sae_mysql_host_m. " <br> "; Echo "From the Library domain name:". sae_mysql_host_s. " <br> "; Echo "Port". Sae_mysql_port. " <br> "; Echo "Database name:". sae_mysql_db. " <br> ";? >
OK, let's start with the specific operation. The following is a detailed analysis of the database operation code used by the public number.
Step1: Use hostname $hostname, and user name password " connect" database .
$link = mysql_connect ($hostname, $dbuser, $dbpass);
STEP2: Use the link information $link, and the information for the database to be manipulated, select the corresponding database .
mysql_select_db ($dbname, $link) or Die (' can\ ' t use dbname: '. mysql_error ());
Step3: Lists the contents of the query command , based on the information you need to query.
$sql = "Select * FROM {$dbname}. ' CRM ' WHERE ' USER ' = ' {$fromUsername} ' LIMIT 0, 30 ';
Use the mysql_query () function to query.
$query = mysql_query ($sql);
STEP4: After obtaining the information, " convert" the information into a usable format and use
$rs = Mysql_fetch_array ($query); Convert data to "PHP's associated data"
$name = $rs [' USER '];
$content = $rs [' content '];
If it is an insert instruction, write the information in the following format
$sql = "INSERT into {$dbname}. ' CRM ' (' ID ', ' USER ') VALUES (NULL, ' {$fromUsername} ') ';
Then call mysql_query ($sql);
//database_ Adding user information $hostname= Sae_mysql_host_m. ': '.Sae_mysql_port; $dbuser=Sae_mysql_user; $dbpass=Sae_mysql_pass; $dbname=sae_mysql_db; $link=mysql_connect($hostname,$dbuser,$dbpass); if(!$link) { die(' Could not connect: '.Mysql_error()); } //Echo ' Connected successfully<br/> '; Select DB mysql_select_db($dbname,$link) or die(' can\ ' t use dbname: '.Mysql_error()); //echo ' Select db '. $dbname. ' Successfully '; $sql= "Select * FROM {$dbname}. ' CRM ' WHERE ' USER ' = ' {$fromUsername} ' LIMIT 0, 30 '; $query=mysql_query($sql); $rs=Mysql_fetch_array($query); $name=$rs[' USER ']; $content=$rs[' CONTENT ']; if($name==$fromUsername) { $content=$content.Date("Y-m-d g:i",Mktime()).$keyword.‘ <br> '; $sql= "UPDATE ' CRM ' SET ' CONTENT ' = ' {$content} ' WHERE ' USER ' = ' {$fromUsername}‘"; mysql_query($sql); $contentStr= "You are an old user and have stored your information"; } Else{ $content=Date("Y-m-d g:i",Mktime()).$keyword.‘ <br> '; $sql= "INSERT into {$dbname}. ' CRM ' (' ID ', ' USER ') VALUES (NULL, ' {$fromUsername}‘)"; mysql_query($sql); $contentStr= "You are a new user, you have stored your information"; } Mysql_close($link);
MySQL basic operation Flow-sae mysql-php