Sina sae official documentation: http://apidoc.sinaapp.com/sae/SaeMysql.html
Class SaeMysql implementation: http://apidoc.sinaapp.com/__filesource/fsource_sae__saemysql.class.php.html
The official Sina documentation provides a simple example:
<?php$mysql = new SaeMysql(); $sql = "SELECT * FROM `user` LIMIT 10";$data = $mysql->getData( $sql );$name = strip_tags( $_REQUEST['name'] );$age = intval( $_REQUEST['age'] );$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();?>
However, I think it is not detailed enough, especially for beginners, maybe this is the style of Daniel. The example is concise and concise.
We generally add, delete, modify, and query databases.
The addition, deletion, and modification operations all execute SQL statements and check whether the statements are correctly executed based on the error code;
Query operations are generally divided into two types:
You can obtain a query record, which is commonly used to query the user name and password during login. The corresponding method getLine () in the SaeMysql class returns a one-dimensional array;
Query to obtain multiple records. The returned result is a two-dimensional array, which requires two layers of foreach for output:
<? Php/** Author: qianshou * Date: 2014/4/28 * Comment: I was going to go to study, and the plan was ruined */$ mysql = new SaeMysql (); // This class completes database connection during initialization. // ================== =======================================$ SQL = "INSERT INTO 'demo _ table' ('id ', 'name', 'Password') VALUES ('', 'qianshou', '000000'), ('', 'naruto', 'abcde '),('', 'akaxi', 'asdfg') "; $ mysql-> runSql ($ SQL); // execute the data insertion Operation if ($ mysql-> errno ()! = 0) {die ("Error:". $ mysql-> errmsg ();} else {echo "Data inserted successfully! <Br/> ";} // ================== perform the data retrieval operation ============================= ============/// retrieve a row of Data $ SQL = "SELECT * FROM 'demo _ table' WHERE 'id' = '1 '"; $ row = $ mysql-> getLine ($ SQL); foreach ($ row as $ key => $ value) {echo $ key. "=> ". $ value. "<br/>" ;}echo "<br/> next demo <br/> "; // retrieve multiple rows of Data $ SQL = "SELECT * FROM 'demo _ table'"; $ result = $ mysql-> getData ($ SQL ); foreach ($ result as $ row) {foreach ($ row as $ key => $ value) {echo $ key. "=> ". $ value. "<br/>";} ec Ho "==============================< br/>" ;}$ mysql-> closeDb ();?>
Output result:
Id => 1
Name => qianshou
Password = & gt; 12345
Next demo
Id => 1
Name => qianshou
Password = & gt; 12345
==============================
Id => 2
Name => naruto
Password => abcde
==============================
Id => 3
Name => kakaxi
Password => asdfg
==============================