0

I just wondering how could this happen, when I try my code on localhost, it works fine. But when I copied the code on hosting, the result wont show up. Could someone tell me what is happening, here is my code

$squery = $config->prepare("SELECT * FROM kbm WHERE nama=? ORDER by tanggal DESC LIMIT ?, ?");
$squery->bind_param("sii", $nama, $curr, $limit);
$squery->execute();
$query = $squery->get_result();
$sqdata = $config->prepare("SELECT * FROM kbm WHERE nama=?");
$sqdata->bind_param("s", $nama);
$sqdata->execute();
$qdata = $sqdata->get_result();

and here is how I access the result

while($row = $query->fetch_assoc()){

At first I thought it was because the PHP version, so I search for solution and I find https://php.watch/versions/8.2/mysqli_execute_query I tried to implement it, but still no result, or did I do it wrong?

  • 1
    Do you have error reporting enabled? ( `error_reporting( E_ALL );` ) and when you make the `mysqli` connection have you enabled error reporting there too using `mysqli_report( MYSQLI_REPORT_ERROR | MYSQLI_REPORT_STRICT );` - try, see if that reveals anything – Professor Abronsius May 20 '23 at 07:17
  • 2
    It happens *all the time* with everyone. And simply means that the problem is not the code but environment. – Your Common Sense May 20 '23 at 07:19
  • By the way, it looks like you are running the second query to get the count. You should never ever do that. See https://phpdelusions.net/mysqli#num_rows – Your Common Sense May 20 '23 at 07:24
  • @YourCommonSense, fyi on hosting I use 8.2 PHP, while on localhost I still use 7, could you help me identify my problem? – M. Agus Tri Mulyono May 20 '23 at 07:49
  • @ProfessorAbronsius yeah, I want to implement an error reporting, but I dont know where to put the code LOL – M. Agus Tri Mulyono May 20 '23 at 07:51
  • 2
    See the duplicate in the blue box, above. It goes before your connection code. But if you're on 8.2 it should be enabled by default, so check the php error log file on the hosting account for existing errors. P.s. it's never a good idea to develop on a different language version than the one you'll use in the live system. That way lies unpleasant surprises – ADyson May 20 '23 at 08:07
  • @ADyson could you help me, when I use `$query = mysqli_query($config, "SELECT * FROM kbm WHERE file LIKE '$like' ORDER by tanggal DESC LIMIT $curr, $limit");` without prepared statement, it works fine. I wonder what happen with my code – M. Agus Tri Mulyono May 21 '23 at 08:50
  • 1
    If you have a new problem with new some different code, you need to post a new question about it, and include the problematic code, so the community can see it and help you properly. Comments cannot receive Answers, and don't show in searches/feeds etc. So they won't get much attention. See the [tour] if you need to understand more about the format and usage of stackoverflow. – ADyson May 21 '23 at 14:05
  • P.s. we don't know exactly what you tried when you used the prepared statements or what error/unexpected behaviour you experienced, but, in general, the topic of using LIKE with prepared statements and parameters has been covered many times already on this site and others, so you can probably solve your issue just with a simple bit of research (assuming that's what the issue relates to specifically) – ADyson May 21 '23 at 14:07

0 Answers0