Working with Databases in PHP
<?PHP//1: Connect the Database (System): mysql_connect ("Database system name/ip/address", "username", "password")Mysql_connect ("localhost","Root","");//mysql_connect () is a PHP built-in function//2: Set the Environment code to perform the database operation: Here the Environment code actually refers to the current PHP file character encoding. mysql_query ("Set names UTF8");//mysql_query () is also a PHP built-in function//3: Select the database you want to manipulatemysql_query ("Use php0910b");//4: Execute the specific SQL statement (INSERT, delete, UPDATE, select)//mysql_query ("INSERT into UserInfo3 (userName, postcode, fee, age, RegDate) VALUES (' test1 ', ' 101010 ', 180.7, 18, ' 2014-10-9 ') "); //in other words, the mysql_query () function can be used to execute almost "all" SQL statements! $sql="Delete from UserInfo3 where id=5";//Typically, a SQL statement (command) is used in the future, usually in PHP with this variable name. Note that this is a PHP string! //in other words, almost any SQL statement can be written here,$result= mysql_query ($sql);//$result represents the result of the mysql_query statement execution, here is a "true and false" value, which is a Boolean value//If the result is true, indicates that the statement executed successfully//If the result is false, it indicates that the statement execution failed. if($result = =true) {echo"Successful Execution! "; } Else{echo"execution failed. We apologize, please contact the administrator. Code Error reference information:" . Mysql_error (); //mysql_error () is used to get the error message when the last SQL statement failed to execute. }?>
How data is submitted (delivered)
Only two: Post,get.
mode one: Post <form action "abc.php" method= "POST" > <input type= "text" name= "S1"/> <input type= " Text "name=" BB "/> </form> gets (receives) its data in PHP in the way: $_post[' data item name value '];
Way two: Get
The Get method commits (passes) data in several forms:
Form 1:
<form action "abc.php" method= "get" > <input type= "text" name= "S1"/> <input type = "text" name= "BB"/> </form>
The way in which to get (receive) its data in PHP is: $_get[' data item's name value '];
Form 2:
<a href= "ABC.PHP?S1=5&BB=18&CC=ABCD" >go go go</a>
Previous Line Description: The link will be delivered from the current page (submit) 3 data to abc.php this page, the first data name is S1, the value is "5", the second data is named BB, the value is "18", the 3rd data name is CC, the value is "ABCD".
Get (receive) its data way: $_get[' data item name ']
Form 3:
<script> = "abc.php?s1=5&bb=&cc=abcd"; </script> Description: In fact, Form 3 is a variant of 2 forms, the same way.
PHP Basic Learning Notes MySQL 2 (15)