<?php
$conn = mysqli_connect(
'localhost', /* The host to connect to 连接MySQL地址 */
'root', /* The user to connect as 连接MySQL用户名 */
'root', /* The password to use 连接MySQL密码 */
'mydatabase'); /* The default database to query 连接数据库名称*/
if (!$conn) {
printf("Can't connect to MySQL Server. Errorcode: %s ", mysqli_connect_error());
exit;
}
$sql="insert into student values('zbc','男','itcast0005',23);";
$result = mysqli_query($conn,$sql);
echo $result;
?>
mysql> select * from student;
+-----------+--------+------------+------+
| name | gender | number | age |
+-----------+--------+------------+------+
| 张越 | 男 | itcast0005 | 22 |
| 张越123 | 男 | itcast0005 | 23 |
+-----------+--------+------------+------+
2 rows in set (0.00 sec)
mysql> select * from student;
+-----------+--------+------------+------+
| name | gender | number | age |
+-----------+--------+------------+------+
| 张越 | 男 | itcast0005 | 22 |
| 张越123 | 男 | itcast0005 | 23 |
| zbc | 男 | itcast0005 | 23 |
+-----------+--------+------------+------+
3 rows in set (0.00 sec)
mysql>