简体   繁体   English

MAMP无法使用PHP将数据插入数据库

[英]MAMP unable to insert data into database with PHP

I've been struggling with this problem for a really long time. 很长一段时间以来,我一直在努力解决这个问题。 The phpmyadmin of MAMP doesn't allow me to insert data into database with php. MAMP的phpmyadmin不允许我使用php将数据插入数据库。 I use object oriented style mysqli, which works as following: 我使用面向对象的样式mysqli,其工作方式如下:

    $sql = "INSERT INTO data(dataid, pic, sen)
            VALUES('$i', '$pic', '$sen')";
    if ($conn->query($sql)) {
        echo  "success<br >";
    } else {
        echo "failure<br >" . $conn->error;
    }

I got "success" as the returning message but nothing is inserted into DB. 返回消息为“成功”,但没有任何内容插入数据库。 As for the SQL, I've checked with database and it is correct. 至于SQL,我已经检查了数据库,它是正确的。

I guess the problem is about privileges but I'm the root user. 我猜问题出在特权上,但我是root用户。 Overall, I can read data from DB with PHP but can't write any to it. 总体而言,我可以使用PHP从DB读取数据,但不能向其中写入任何数据。 Does anyone know the answer to the problem? 有人知道问题的答案吗?

I really appreciate your help and effort. 我非常感谢您的帮助和努力。

How did you connect to the database? 您是如何连接到数据库的? If you are using the mysqli_real_connect() as officially recommended, you could try just use mysqli($host, $user, $password, $db, $port) instead. 如果按照官方建议使用mysqli_real_connect(),则可以尝试仅使用mysqli($ host,$ user,$ password,$ db,$ port)。 Worked for me. 为我工作。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM