php Mysql

作者: 曾柏超 | 来源:发表于2018-02-10 20:42 被阅读0次
    
    <?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> 
    

    相关文章

      网友评论

          本文标题:php Mysql

          本文链接:https://www.haomeiwen.com/subject/xhehtftx.html