Mysql Explain problems

PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!

Moderator: General Moderators

Post Reply
bowlesj
Forum Contributor
Posts: 179
Joined: Fri Jul 18, 2014 1:54 pm

Mysql Explain problems

Post by bowlesj »

Hi, I am trying to get the MySql EXPLAIN keyword to work. The code below is the top part of a PHP script with the MySql command. It works fine until I put in the EXPLAIN keyword (does not matter if the EXTENDED is in there). I am using PHP 5.5.11 on Xampp. When I put the EXPLAIN in I get "Undefined index: fldMM_AnnounceDateTime" so the MySql command is not working. However the mysqli_error($con) command is not adding anything to the message being fed into the error handler defined at the top. When I get this thing to work, am I suppose to see the EXPLAIN output in the PHP log? In the PHP ini file I have all output redirected to the error handler (well standard output is shut off). I hope I don't need to turn off the error handler which sends an email to me. The error handler is such an improvement over what I was doing before which was nothing short of awful - LOL.
Thanks,
John

Code: Select all

<?php
Include 'Mod_MyErrorHandler.php';
Include 'Mod_session_start.php';
if (!isset($_SESSION['login'])) {
   trigger_error("Login SESSION is not set",E_USER_ERROR);
   die();
}
Include 'Mod_Connect_DB.php';

$fldMM_Key = $_SESSION['fldMM_Key'];
$fldMM_MemberType_LU = $_SESSION['fldMM_MemberType_LU'];

$sqlMM = "
   EXPLAIN EXTENDED SELECT 
      tblMemberMaster.fldMM_AnnounceDateTime
   FROM
      tblMemberMaster
   WHERE
      tblMemberMaster.fldMM_Key = '$fldMM_Key';
";
$resultMM = @mysqli_query($con,$sqlMM);
if (!$resultMM) {
   $result = "Error retrieving member master (data) 1. "  . mysqli_error($con);
   trigger_error($resultMM,E_USER_ERROR);
}
$rowMM = @mysqli_fetch_array($resultMM);
if (!$rowMM) {
   $result = "Error retrieving member master (data) 2. "  . mysqli_error($con);
   trigger_error($resultMM,E_USER_ERROR);
}
$fldMM_AnnounceDateTime = $rowMM['fldMM_AnnounceDateTime'];

User avatar
Celauran
Moderator
Posts: 6427
Joined: Tue Nov 09, 2010 2:39 pm
Location: Montreal, Canada

Re: Mysql Explain problems

Post by Celauran »

You're asking for a column that you'd get for the regular query. EXPLAIN changes the output and is something I've always run through the console, not through PHP. What is it you're trying to do here?
bowlesj
Forum Contributor
Posts: 179
Joined: Fri Jul 18, 2014 1:54 pm

Re: Mysql Explain problems

Post by bowlesj »

Thanks Celauran.

Your answer did the trick. I just ran it through MySql Workbench and I got the output. It is just a test on a simple query in prep for analyzing some of the big queries that I want to make sure are running as good as I can get them to run. I want to do everything I can to get this website to run as fast as possible (for these big queries especially) and if need be (and if income warrants it) I may hire an expert to look things over to see if they can make it better (I will deal with that when the time comes which will probably be at least a few years away).

I like your new icon. I use to drink coffee a lot but stopped completely when my heart palpitations got out of hand. They are better than average now.

John
Post Reply