热门标签 | HotTags
当前位置:  开发笔记 > 编程语言 > 正文

这个mysqli_query不会执行[重复]-Thismysqli_querywillnotexecute[duplicate]

Thisquestionalreadyhasananswerhere:这个问题在这里已有答案:HowtogetMySQLierrorinformatio

This question already has an answer here:

这个问题在这里已有答案:

  • How to get MySQLi error information in different environments 2 answers
  • 如何在不同环境中获取MySQLi错误信息2答案

This is my code using OO style:

这是我使用OO风格的代码:

$query = "SELECT * FROM articles LIMIT 1";
$result=mysqli_query($db, $query) or die("Could Not execute query.");
$row = $result->fetch_assoc()
echo $row;

Code using Procedural:

代码使用程序:

$query = "SELECT * FROM articles LIMIT 1";
$result=mysqli_query($db, $query) or die("Couldn't execute query.");
$row = mysqli_fetch_row($result);
echo $row;

I have tried various different ways of getting this to work and the query never seems to execute.

我已经尝试了各种不同的方法来使这个工作,并且查询似乎永远不会执行。

I am new to mysqli from mysql and am struggling with some of the differences. Apologies if there is an obvious answer to this question.

我是mysql的mysqli的新手,我正在努力解决一些差异。如果对这个问题有明显的答案,请道歉。

Any Help much appreciated.

任何帮助非常感谢。

2 个解决方案

#1


0  

Try:

$query  = "SELECT * FROM articles LIMIT 1";
$mysqli = mysqli_connect("example.com", "user", "password", "database");
$res = mysqli_query($mysqli, $query);
$row = mysqli_fetch_assoc($res);

or:

$mysqli = new mysqli("example.com", "user", "password", "database");
$res = $mysqli->query($query);
$row = $res->fetch_assoc();

#2


0  

Assuming your

 $db = mysqli_connect("localhost", "user", "password", "database");

then you can have

那么你可以拥有

$query  = "SELECT * FROM articles LIMIT 1";
$res = $db->query($query);
$row = $res->fetch_assoc();

推荐阅读
author-avatar
潮人搭配师er氵ic_161
这个家伙很懒,什么也没留下!
PHP1.CN | 中国最专业的PHP中文社区 | DevBox开发工具箱 | json解析格式化 |PHP资讯 | PHP教程 | 数据库技术 | 服务器技术 | 前端开发技术 | PHP框架 | 开发工具 | 在线工具
Copyright © 1998 - 2020 PHP1.CN. All Rights Reserved | 京公网安备 11010802041100号 | 京ICP备19059560号-4 | PHP1.CN 第一PHP社区 版权所有