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...
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.
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
...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
mixed mysqli_query ( mysqli $link , string $query [, int $resultmode = MYSQLI_STORE_RESULT ] )
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.