Home Upgrade Search Memberlist Extras Hacker Tools Award Goals Help Wiki Contact

PHP 

mysql_fetch_array to mysqli

Im trying to update my code to mysqli to make it php 7 ready so i updated the db connection and now it works fine however executing and getting result from a query doesnt give any response anyone knows what im doing wrong ?
here the part
PHP Code

<?php 
$sql
="SELECT * FROM tbl_uploads";
        
$result_set=mysqli_query($sql);
        while(
$row=mysqli_fetch_array($result_set)) 
=============================================
Nothing yet
=============================================
(Oct 3, 2017 06:48 AM)deadsh0t Wrote:  Im trying to update my code to mysqli to make it php 7 ready so i updated the db connection and now it works fine however executing and getting result from a query doesnt give any response anyone knows what im doing wrong ?
here the part
PHP Code

<?php 
$sql
="SELECT * FROM tbl_uploads";
        
$result_set=mysqli_query($sql);
        while(
$row=mysqli_fetch_array($result_set)) 

if you run the following code:
PHP Code

<?php 
$sql
="SELECT * FROM tbl_uploads";
        
$res = mysqli_query($sql);
        
var_dump(mysqli_fetch_array($result_set)); 

And you get a NULL response, you should run the same query locally on the DB to insure it actually returns data.
(Jul 12, 2023 04:49 AM)-Scrub Wrote:  i fucked my friend in the ass while he sucked off his friend and then switched and then my friend fucked his friend in the ass and i fucked my friends friend in the ass and we all cummed on my friends friend..
(Oct 3, 2017 09:24 AM)Lrrr Wrote:  if you run the following code:
PHP Code

<?php 
$sql
="SELECT * FROM tbl_uploads";
        
$res = mysqli_query($sql);
        
var_dump(mysqli_fetch_array($result_set)); 

And you get a NULL response, you should run the same query locally on the DB to insure it actually returns data.

If i change it back to mysql instead of mysqli it works fine the query returns data it inly turns to no result when trying to convert it to mysqli
=============================================
Nothing yet
=============================================
(Oct 3, 2017 09:35 AM)deadsh0t Wrote:  If i change it back to mysql instead of mysqli it works fine the query returns data it inly turns to no result when trying to convert it to mysqli

because u need to pass a mysqli instance to mysqli_query

example:

PHP Code

<?php 
$mysqli 
= mysqli_connect("localhost", "my_user", "my_password", "world");
$sql="SELECT * FROM tbl_uploads";
$result_set=mysqli_query($mysqli, $sql);
while(
$row=mysqli_fetch_array($result_set)) 
Also either use mysqli_fetch_assoc instead of mysqli_fetch_array or use the second parameter of mysqli_fetch_array.
You see, Doctor, God didn't kill that little girl. Fate didn't butcher her and destiny didn't feed her to those dogs.
If God saw what any of us did that night he didn't seem to mind. From then on I knew... God doesn't make the world this way.
We do.
(Oct 3, 2017 10:43 AM)remix.cpp Wrote:  because u need to pass a mysqli instance to mysqli_query

example:

PHP Code

<?php 
$mysqli 
= mysqli_connect("localhost", "my_user", "my_password", "world");
$sql="SELECT * FROM tbl_uploads";
$result_set=mysqli_query($mysqli, $sql);
while(
$row=mysqli_fetch_array($result_set)) 

Yeah this worked thanks however i include a dbconfig.php at the beginning at the file can you explain why i needed t open a new connection instead of using the connection already present ?
Or is this specific for mysqli ?
=============================================
Nothing yet
=============================================
(Oct 3, 2017 01:02 PM)deadsh0t Wrote:  Yeah this worked thanks however i include a dbconfig.php at the beginning at the file can you explain why i needed t open a new connection instead of using the connection already present ?
Or is this specific for mysqli ?

http://php.net/manual/en/mysqli.query.php
Quote:link
Procedural style only: A link identifier returned by mysqli_connect() or mysqli_init()

You see, Doctor, God didn't kill that little girl. Fate didn't butcher her and destiny didn't feed her to those dogs.
If God saw what any of us did that night he didn't seem to mind. From then on I knew... God doesn't make the world this way.
We do.
(Oct 3, 2017 01:12 PM)Squito Wrote:  http://php.net/manual/en/mysqli.query.php

Thanks! this explained it pretty well
=============================================
Nothing yet
=============================================
(Oct 3, 2017 06:48 AM)deadsh0t Wrote:  Im trying to update my code to mysqli to make it php 7 ready so i updated the db connection and now it works fine however executing and getting result from a query doesnt give any response anyone knows what im doing wrong ?
here the part
PHP Code

<?php 
$sql
="SELECT * FROM tbl_uploads";
        
$result_set=mysqli_query($sql);
        while(
$row=mysqli_fetch_array($result_set)) 

PHP Code

<?php 
$connection 
= mysqli_connect("host","user","pass","dbname");

$sql="SELECT * FROM tbl_uploads";
        
$result_set=mysqli_query($connection,$sql);
        while(
$row=mysqli_fetch_array($result_set)) 

I think you need to include the connection on the query
(Oct 3, 2017 06:48 AM)deadsh0t Wrote:  Im trying to update my code to mysqli to make it php 7 ready so i updated the db connection and now it works fine however executing and getting result from a query doesnt give any response anyone knows what im doing wrong ?
here the part
PHP Code

<?php 
$sql
="SELECT * FROM tbl_uploads";
        
$result_set=mysqli_query($sql);
        while(
$row=mysqli_fetch_array($result_set)) 

mysqli_query requires 2 parameters

1.) Mysqli Database link
2.) Query

You're giving it only the query.
Professional Programming Service
( Front & Back-end Development )


Contact Me


Possibly Related Threads...
Thread / Author Replies Views Last Post
[PHP] by CodepacksJun 26, 2019 08:20 PM 3 176 Jun 26, 2019 08:20 PM
Last Post: Oxycodone
[PHP] by SharoKurdiFeb 16, 2018 02:41 PM 10 413 Feb 16, 2018 02:41 PM
Last Post: blackcoder00
[PHP] by JASDec 19, 2017 08:57 AM 8 224 Dec 19, 2017 08:57 AM
Last Post: JAS