The connection

Connect to mysql 5.5

<? $db_host = "localhost"; // localhost:3306 $db_port = "3306"; $db_user = "root"; $db_pass = "root"; $db_name = "test"; $charset = "utf8"; If (! $db_host.":".$db_port,$db_user,$db_pass)) {echo" </h2>"; Echo "system error: ". Mysqli_connect_error (); die(); } //(3) select the current database if(! Mysqli_select_db ($link,$db_name)) {echo "<h2> select db($link,$db_name); </h2>"; die(); } //($link,$charset); Mysqli_close ($link);Copy the code

Execute various SQL statements

Mysqli_query () : sends a MySQL query; Syntax: resource mysqli_query(mysqli link,stringlink,stringlink,stringquery) Query is a query string; Query is a query string; Link is the active database connection created; Note: mysqli_query() returns a mysqli_result result set object only for SELECT, SHOW, or DESCRIBE statements, or FALSE if the query is not executed correctly. For other types of SQL statements, mysqli_query() returns TRUE on success and FALSE on error. A return value that is not FALSE means that the query is valid and can be executed by the server. Note: The query string should not end with a semicolon, as in command line mode.

$sql_student_query = "select * from student";
$sql_student_update = "update student set name = 'xxxxx' where id = 27";

echo "<hr>";
var_dump(mysqli_query($link.$sql_student_query));

echo "<hr>";
var_dump(mysqli_query($link.$sql_student_update));
Copy the code