简体   繁体   English

mysql_到mysqli_转换问题

[英]mysql_ to mysqli_ Conversion Problems

I have a small website that I wanted to switch over to the mysqli_* functions, and after reading up a lot on it I decided to do the switch by doing a replace-all mysql_ with mysqli_ -- I then went through and verified that everything changed correctly... 我有一个小网站,我想切换到mysqli_ *函数,在阅读 了很多内容后,我决定通过mysql_替换所有mysql_进行mysqli_ - 然后我通过并验证了所有内容改变正确...

Now, the mysqli_connect() works - (I get a valid resource connection back from it) but further down the PHP script I have a mysqli_query function that is returning NULL no matter what I put in as the SQL. 现在, mysqli_connect()工作 - (我从它获得了一个有效的资源连接)但是在PHP脚本的下方,我有一个mysqli_query函数,无论我把它作为SQL放入什么,它都会返回NULL

Any thoughts what could be happening? 有什么想法会发生什么?

The relevant code: 相关代码:

function connecti_database() {
  mysqli_connect(DB_HOST, DB_USER, DB_PASS, DB_DATABASE);
}

connecti_database();
$sql = 'SELECT * FROM table where id = 5';
$result = mysqli_query($sql);
var_dump($result); // this returns NULL every time

mysqli functions require two parameters, not one mysqli函数需要两个参数,而不是一个
...and a developer required to read documentation first. ......以及开发人员需要先阅读文档

function connecti_database() {
  global $mysqli;
  $mysqli = mysqli_connect(DB_HOST, DB_USER, DB_PASS, DB_DATABASE);
  mysqli_select_db($mysqli,DB_DATABASE);
}

connecti_database();
$sql = 'SELECT * FROM table where id = 5';
$result = mysqli_query($mysqli, $sql);

PHP Manual: http://php.net/manual/en/mysqli.query.php PHP手册: http//php.net/manual/en/mysqli.query.php

mixed mysqli_query ( mysqli $link , string $query [, int $resultmode = MYSQLI_STORE_RESULT ] )

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM