dou7851 2015-03-11 13:38
浏览 18
已采纳

为什么我的php绑定param代码可以在wamp上运行,但它在lnmp平台上不起作用

My code is quite simple.It is about submit some data to mysql database. It did work to use normal way to submit data like query(). Code is here:

$con = new mysqli('127.0.0.1','xxx','xxx','xxx');
$con->query("SET NAMES 'utf8'");
$stmt=$con->prepare("INSERT INTO comments (Nickname, Content, Img) VALUES (?, ?, ?)");
$stmt->bind_param('sss', $nickname, $comments, $proc_comments);
$stmt->execute();

When I submitted to this php webpage, it did not pointing out any mistakes. I'm a university student who are not majoring CS or other relative subjects.Please help me.Thanks.

Update: This following code can work on the lnmp platform.

    $con = new mysqli('localhost','user','passwd','database_name');
    $con->query("SET NAMES 'utf8'");
    $stmt=$con->prepare("UPDATE comments SET Likes=Likes+1 WHERE Num=?");
    $stmt->bind_param('i',$favor_num);
    $stmt->execute();

Last update: I try to check Nginx's error log to see if there is any mistake I missed, but it did not have any problem relative to this strange thing.

  • 写回答

2条回答 默认 最新

  • doulu4976 2015-03-11 14:06
    关注

    It could be many things, but since you have different results on different environments, the two most likely causes are:

    1. Your lnmp platform wasn't compiled with mysqli support. Check by creating a page called 'phpinfo.php' with only <?php phpinfo(); in it. Load that page in your browser, and make sure there's a section with 'mysqli' as its title. Read its description and verify it's there.

    2. Your connection data is different on LNMP. It could be as simple as the database name, user name, and password are different on your LNMP box and need to be reconfigured. Go to a terminal, and type mysql -u <username> -p <databasename> then when prompted verify you can query the database (e.g. do a SHOW TABLES;, SELECT * FROM comments, etc.) If you can query it, but you can't manually run that 'INSERT INTO...' from above, then your user is setup but doesn't have correct permissions to do an insert on that table. Google around for MySQL help with configuring that.

    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论
查看更多回答(1条)

报告相同问题?

悬赏问题

  • ¥15 r语言Hurst指数
  • ¥15 Acrn IVSHMEM doorbell问题
  • ¥15 yolov5中的val测试集训练时数量变小问题
  • ¥15 MPLS/VPN实验中MPLS的配置问题
  • ¥15 materialstudio氢键计算问题
  • ¥15 echarts图表制作
  • ¥15 halcon根据玻璃面板纹路取区域
  • ¥15 HFSS设计小型化180度耦合器
  • ¥15 使用CInternetSession,CHttpFile读取网页文件时有些电脑上会卡住怎么办?
  • ¥15 水下机器人的半物理仿真研究