在获取mysqli_query执行时遇到问题 [英] Having a problem getting mysqli_query to execute

查看:72
本文介绍了在获取mysqli_query执行时遇到问题的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

这是问题:我今天开始使用mysqli进行交换.没什么大不了的,只需要更改一些声明即可.一切正常,没有错误...除了我根本无法执行任何查询.我已经检查了我的语法两次和三次.我什至开始创建一种情况,它应该返回一个错误(试图将其插入到不存在的表中或值超出列限制或与类型不匹配的表中)并且...什么都没有.它不会返回错误,也不会写入.如果参数一不是mysqli类型,它将抱怨.

Here's the problem: I started a swap today to use mysqli. No biggie, just had to change a few statements. Everything went fine, no errors... Except that I can't get it to execute any queries at all. I have double and triple checked my syntax. I even started creating situations where it SHOULD return an error (Trying to get it to INSERT to Tables that don't exist or with values that exceeded column limits or didn't match type) and... nothing. It doesn't return an error, it doesn't write. It WILL complain if parameter one is NOT a mysqli type.

以下是相关代码:

$con = mysqli_connect("localhost", "root", "","test");

if (mysqli_connect_errno()) {
printf("Connect failed: %s\n", mysqli_connect_error());
exit();
}

$query = "INSERT INTO files VALUES (NULL, 5, 'hello')";
mysqli_query($con, $query);

什么也没有.它运行没有问题,但从未写入记录.我什至可以将$ query更改为"hdjhkfhhjfkd",它运行没有问题. mysqli_query()暂时没有执行.我唯一能使它作出反应的是,如果我将$ con更改为其他任何内容,则它抱怨它需要mysqli类型.

And nothing. It runs without a problem, but it never writes the record. I can even change the $query to "hdjhkfhhjfkd" and it runs no problem. mysqli_query() just isn't executing, period. The only time I can get it to react is if I change $con to anything else, then it complains that it needs a mysqli type.

有什么想法吗?这使我疯狂.

Thoughts? THis is driving me bonkers.

推荐答案

您是否检查了mysqli_query()的返回值?如果发生错误,则返回FALSE.在这种情况下, mysqli_error()为您提供有关该错误的更多信息.

Have you checked the return value of mysqli_query()? It returns FALSE if an error occurred. In that case mysqli_error() gives you more information about the error.

<?php
$con = mysqli_connect("localhost", "root", "", "test");
if (mysqli_connect_errno()) {
  printf("Connect failed: %s\n", mysqli_connect_error());
  exit();
}

$query = "INSERT INTO files VALUES (NULL, 5, 'hello')";
echo "<pre>Debug: $query</pre>\m";
$result = mysqli_query($con, $query);
if ( false===$result ) {
  printf("error: %s\n", mysqli_error($con));
}
else {
  echo 'done.';
}

这篇关于在获取mysqli_query执行时遇到问题的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆