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 删除虚拟显示器驱动 删除所有 Xorg 配置文件 删除显示器缓存文件 重启系统 可是依旧无法退出虚拟显示器
  • ¥15 vscode程序一直报同样的错,如何解决?
  • ¥15 关于使用unity中遇到的问题
  • ¥15 开放世界如何写线性关卡的用例(类似原神)
  • ¥15 关于并联谐振电磁感应加热
  • ¥60 请查询全国几个煤炭大省近十年的煤炭铁路及公路的货物周转量
  • ¥15 请帮我看看我这道c语言题到底漏了哪种情况吧!
  • ¥66 如何制作支付宝扫码跳转到发红包界面
  • ¥15 pnpm 下载element-plus
  • ¥15 解决编写PyDracula时遇到的问题