<?PHP$con[Email protected]mysql_connect(' localhost ', ' root ', ', ' 3306 '); if(!$con){ die(' Connection failed '.Mysql_error()); }Else{ Echo' Connected successfully! ‘; } mysql_query(' Set name UTF8 ',$con); mysql_select_db(' Kun ',$con); $result=mysql_query(' SELECT * from T ',$con) or die(Mysql_error()); //$result =mysql_query (' Select COUNT (*) from T '); $row =mysql_fetch_row (); echo $row [0]; DQL First output: (Recommended with Mysql_fetch_row () and MYSQL_FETCH_ASSOC)//performance is highest, you must know the column number of the query data (that is, the index 0123) while($row=Mysql_fetch_row($result)){ Echo $row[0]. ' <br/> '; } /*While ($row =mysql_fetch_array ($result)) {//Returns an indexed array and an associative array//Echo $row [3]. ' <br/> ';//The data is more used, the lowest efficiency, the deposit of double (Index and association) [0] = laughing and joking [name], and laughing and joking Print_r ($row); } */ /*While ($row =mysql_fetch_assoc ($result)) {//Returns an associative array echo $row [' name ']. ' <br/> '; } */ while($row-Mysql_fetch_object($result)){//returns an object Echo $row-uid; } //the second output: while($row=$result-Fetch_row ()) { foreach($row as $key=$a){ Echo" --$a-- "; } } //DML Output: $result=mysql_query(' delete from T where id=3 ',$con); or$result=mysql_query(' INSERT into T (uname) value (' Wang ') ',$con); or$result=mysql_query(' Update t set uagree=43 where id=2 ',$con); $lastInsertId=mysql_insert_id();//gets the last inserted ID, only valid for insert if(!$result){ die(' Operation failed '.Mysql_error()); } if(mysql_affected_rows($con) >0){ Echo"Operation succeeded"; }Else{ Echo"Row count not affected"; } Mysql_free_result($result);//releasing the resulting memory DML does not require this, as this frees the resource type, whereas the $result in DML is of type bool Mysql_close($con);//Close the database (can not write, will automatically close, suggested write) /*Expand: \s or Show tables view the current user's database Netstat–an view network connection Status Var_dump () view type Send directives include (DDL data definition statement, DQL (Sele CT), return MySQL result DML data Operation statement Update delete INSERT, return BOOL DTL data TRANSACTION statement Rollback commit ... )*/
MySQL Connection database