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条)

报告相同问题?

悬赏问题

  • ¥20 有关区间dp的问题求解
  • ¥15 多电路系统共用电源的串扰问题
  • ¥15 slam rangenet++配置
  • ¥15 有没有研究水声通信方面的帮我改俩matlab代码
  • ¥15 对于相关问题的求解与代码
  • ¥15 ubuntu子系统密码忘记
  • ¥15 信号傅里叶变换在matlab上遇到的小问题请求帮助
  • ¥15 保护模式-系统加载-段寄存器
  • ¥15 电脑桌面设定一个区域禁止鼠标操作
  • ¥15 求NPF226060磁芯的详细资料