Jump to content

mysql output lost without a "word"


ajoo

Recommended Posts

Hi all, 

My server config is as below

Server version: Apache/2.4.18 (Ubuntu)
PHP 7.0.30-0ubuntu0.16.04.1 (cli) ( NTS )
mysql  Ver 14.14 Distrib 5.7.22, for Linux (x86_64) using  EditLine wrapper

I have this following bit of code. It runs up-to a point, indicated by the comments in code, and then vanishes totally. There is no error and there is no output either. I have display errors and mysqli reporting on and set as below: 

							ini_set("display_errors",1);

							mysqli_report(MYSQLI_REPORT_ERROR | MYSQLI_REPORT_STRICT);
							$mysqliDriver = new mysqli_driver();
							$mysqliDriver->report_mode = MYSQLI_REPORT_ERROR | MYSQLI_REPORT_STRICT;	
								case "VS":
								
								$prestr = $sent_result[8];
								$STATUS = $prestr."Status";
								$SUMS = $prestr."Sums";
								$PCT = $prestr."PCT";
								$DPM = $prestr."DPM";
								$TIMETAKEN = $prestr."TimeTaken";
								$SPEEDDIGITS = $prestr."SpeedDigits";
								$SPEEDSUMS = $prestr."SpeedSums";		
								$MODULE 	= $prestr."mistakes";	

								if($STATUS=='1'){ throw new Exception("VISUAL GADBAD"); } 
																		
								$v_sums_correct = $sent_result[1];
								$v_time_in_seconds = $sent_result[2];
								$v_delay_digit_ms = $sent_result[3];
								$v_delay_sum_ms = $sent_result[4];
								$v_dpm = $sent_result[5];
								$v_pct = $sent_result[6];
								$v_WA = $sent_result[7];

								$con->autocommit(false);		
								$commit_flag = true;			

								$query = "SELECT EXISTS(SELECT 1 from vis_mistakes where UserLogin=? AND DayID = ?) as `mistakesCheck`";
								$stmt = $con->prepare($query);
								$stmt->bind_param('si',$user,$dayNum);
								if($stmt->execute())
								{
									$stmt->bind_result($mistakesCheck);
									$stmt->fetch();
									$stmt->free_result();

									if($mistakesCheck === 0)
									{
										// echo "MODULE : ".$MODULE."<br>";

										 echo "Inside Insert Mistakes<br>";
										$query = "INSERT into `vis_mistakes` (DayID,UserLogin,$MODULE) VALUES (?,?,?)";	
										$stmt = $con->prepare($query);
										$stmt->bind_param('iss',$dayNum,$user,$v_WA); 								
									}else
									{
										echo "Inside Update Mistakes<br>";
										$query = "UPDATE vis_mistakes SET $MODULE = ? WHERE UserLogin = ? AND DayID = ?";
										$stmt = $con->prepare($query);
										$stmt->bind_param('ssi',$v_WA,$user,$dayNum);	// OR die("Bound Fail Vis". $con->error);
									}
									
//								echo $no_of_logins." : ".$time_of_nLogin." : ".$v_sums_correct." : ".$v_pct." : ".$v_dpm." : ".$v_time_in_seconds." : ".$v_delay_digit_ms." : ".$v_delay_sum_ms." : ".$date." : ".$RecNo."<br><br>";

//								echo "<br>".$SUMS." : ".$PCT." : ".$DPM." : ".$TIMETAKEN." : ".$SPEEDDIGITS." : ".$SPEEDSUMS." : ".$STATUS."<br><br>";
									
// **********  // vanishes beyond here ******* !!!!!!
									if($stmt->execute())	
									{
										echo "Generating Query";	// ********* does not display this echo ************* //
										$query = "UPDATE mysessdata SET
												no_of_logins = ?,				
												time_of_nLogin = ?,				
												$SUMS =  ?,							
												$PCT = ?,						
												$DPM = ?,						
												$TIMETAKEN = ?,					
												$SPEEDDIGITS = ?,				
												$SPEEDSUMS = ?,					
												$STATUS = 1,
												TimeOfLogout = ?					
												WHERE RecNo = ?";				
										$stmt = $con->prepare($query);
										$stmt->bind_param('isiddsiisi',$no_of_logins, $time_of_nLogin, $v_sums_correct, $v_pct, $v_dpm, 
															$v_time_in_seconds, $v_delay_digit_ms, $v_delay_sum_ms, $date, $RecNo);
										echo "<br>";
										echo $query;
										echo "<br>";
										
										
										if($stmt->execute())
										{
											echo "<br>Query executed<br>";
											$query = "SELECT $SUMS,$TIMETAKEN,no_of_logins,$SPEEDDIGITS,$SPEEDSUMS FROM $table WHERE RecNo = ? AND $STATUS = 1";
											$stmt=$con->prepare($query);
											$stmt->bind_param('i',$RecNo);
											if($stmt->execute())
											{
												$stmt->bind_result($vsc,$vtt,$no_of_logins,$VDS,$VSS);
												$stmt->store_result();
												$stmt->fetch();
												$stmt->free_result();

												$arr_result =array($datatype,$vsc,0,$vtt);

											//	echo "<br>vsc = ".$vsc;     // server_mod
											//	echo " vtt = ".$vtt;     // server_mod 
											//	echo " Visual Record Updated. <br>";   // server_mod
											//	echo " Visual Speed Digits = ".$VDS;
											//	echo " Viasual Speed SUMS = ".$VSS;

											}
											$con->commit();		
											$con->autocommit(true);
										}
										else
										{
			// ** does not even print this, the else from above  !!!!!! //
										echo "<br>MeesUP";
										throw new Exception("ERROR : 1-V");
										}
									}else  throw new Exception("ERROR : 2-V");			
								}else  throw new Exception("ERROR : 3-V");

								if($commit_flag===false)	
								{
									mysqli_rollback($con);
									throw new Exception("Visual");
								}
								echo " exiting";
								break;

 

SNAPSHOTS OF MY DATABASE

Quote

Database changed
mysql> select RecNo, Wrt_W_Sums_R1,Wrt_W_Sums_R2, Wrt_V_Sums, Wrt_O_Sums, Wrt_W_Status, Wrt_V_Status, Wrt_O_Status, Sessionstatus from mysessdata where UserLogin="mina12345";
+-----------+----------------------------+---------------------------+---------------------+----------------------+----------------------+-----------------------+-----------------------+-----------------------+
| RecNo | Wrt_W_Sums_R1 | Wrt_W_Sums_R2 | Wrt_V_Sums | Wrt_O_Sums | Wrt_W_Status | Wrt_V_Status | Wrt_O_Status | Sessionstatus |
+-----------+----------------------------+----------------------------+--------------------+----------------------+-----------------------+----------------------+-----------------------+-----------------------+
|           1 |                             4 |                             0 |                     4 |                      4 |                        1 |                       1 |                        1 |           1             |
|           8 |                             3 |                             1 |             NULL |               NULL |                        1 |                NULL |                NULL |           NULL     |
+-----------+----------------------------+----------------------------+--------------------+----------------------+-----------------------+----------------------+-----------------------+-----------------------+
2 rows in set (0.00 sec)

mysql> select * from vis_mistakes where UserLogin = "mina12345";
+-----------+-------------------+----------+---------------------------+-------------------------+---------------------------+--------------------------+
| SNo      | UserLogin   | DayID | Wrt_V_mistakes | Mtl_V_mistakes | Mul_V_mistakes | Div_V_mistakes |
+-----------+-------------------+----------+---------------------------+-------------------------+---------------------------+--------------------------+
|           1 | mina12345 |     1     | 3,                            | NULL                  | NULL                     | NULL                   |
|         35 | mina12345 |     2     | 2,3,                         | NULL                  | NULL                     | NULL                   |
+-----------+-------------------+----------+---------------------------+-------------------------+---------------------------+--------------------------+
2 rows in set (0.00 sec)

The NULL values should be changed (updated or inserted).

The output from running the above code is as below :

Quote

array(13) { ["runGend"]=> string(6) "female" ["runType"]=> string(6) "normal" ["v_WA"]=> string(4) "3,4," ["v_pct"]=> string(2) "50" ["v_dpm"]=> string(16) "6.66666666666667" ["v_time_in_seconds_end"]=> string(2) "80" ["v_time_in_seconds_start"]=> string(1) "8" ["v_speed_quantum"]=> string(9) "undefined" ["v_delay_sum_ms"]=> string(4) "5000" ["v_delay_digit_ms"]=> string(4) "2500" ["v_time_in_seconds"]=> string(2) "72" ["v_sums_correct"]=> string(1) "2" ["dataType"]=> string(2) "VS" } 
CountC = 1 Today is 2
Record No is 8
Inside Update Mistakes
Day ID : 2
User : mina12345
WA : 3,4,
8 : 2018-07-24 13:43:45 : 2 : 50 : 6.6666666666667 : 72 : 2500 : 5000 : 24-07-2018 : 8


Wrt_V_Sums : Wrt_V_PCT : Wrt_V_DPM : Wrt_V_TimeTaken : Wrt_V_SpeedDigits : Wrt_V_SpeedSums : Wrt_V_Status

// output of the query.
UPDATE mysessdata SET no_of_logins = ?,    time_of_nLogin = ?,    Wrt_V_Sums = ?,    Wrt_V_PCT = ?,    Wrt_V_DPM = ?,    Wrt_V_TimeTaken = ?,    Wrt_V_SpeedDigits = ?,    Wrt_V_SpeedSums = ?, Wrt_V_Status = 1, TimeOfLogout = ?    WHERE RecNo = ?
 

***** nothing, no output beyond this and no errors either !!

 

The database file, just in case  :?

-- MySQL dump 10.13  Distrib 5.7.22, for Linux (x86_64)
--
-- Host: localhost    Database: mysessdb
-- ------------------------------------------------------
-- Server version	5.7.22-0ubuntu0.16.04.1

/*!40101 SET @OLD_CHARACTER_SET_CLIENT=@@CHARACTER_SET_CLIENT */;
/*!40101 SET @OLD_CHARACTER_SET_RESULTS=@@CHARACTER_SET_RESULTS */;
/*!40101 SET @OLD_COLLATION_CONNECTION=@@COLLATION_CONNECTION */;
/*!40101 SET NAMES utf8 */;
/*!40103 SET @OLD_TIME_ZONE=@@TIME_ZONE */;
/*!40103 SET TIME_ZONE='+00:00' */;
/*!40014 SET @OLD_UNIQUE_CHECKS=@@UNIQUE_CHECKS, UNIQUE_CHECKS=0 */;
/*!40014 SET @OLD_FOREIGN_KEY_CHECKS=@@FOREIGN_KEY_CHECKS, FOREIGN_KEY_CHECKS=0 */;
/*!40101 SET @OLD_SQL_MODE=@@SQL_MODE, SQL_MODE='NO_AUTO_VALUE_ON_ZERO' */;
/*!40111 SET @OLD_SQL_NOTES=@@SQL_NOTES, SQL_NOTES=0 */;

--
-- Table structure for table `mysessdata`
--

DROP TABLE IF EXISTS `mysessdata`;
/*!40101 SET @saved_cs_client     = @@character_set_client */;
/*!40101 SET character_set_client = utf8 */;
CREATE TABLE `mysessdata` (
  `RecNo` int(11) NOT NULL AUTO_INCREMENT,
  `UserLogin` varchar(30) COLLATE utf8_unicode_ci DEFAULT NULL,
  `Level` tinyint(4) NOT NULL,
  `SessionStatus` varchar(3) COLLATE utf8_unicode_ci DEFAULT NULL,
  `TimeOfLogin` datetime DEFAULT NULL,
  `Wrt_W_Sums_R1` tinyint(4) DEFAULT NULL,
  `Wrt_W_Sums_R2` tinyint(4) DEFAULT NULL,
  `Wrt_W_PCT` float(10,2) DEFAULT NULL,
  `Wrt_W_DPM` float(10,2) DEFAULT NULL,
  `Wrt_W_TimeTaken` smallint(6) DEFAULT NULL,
  `Wrt_W_Status` tinyint(4) DEFAULT NULL,
  `Wrt_V_Sums` tinyint(4) DEFAULT NULL,
  `Wrt_V_PCT` float(10,2) DEFAULT NULL,
  `Wrt_V_DPM` float(10,2) DEFAULT NULL,
  `Wrt_V_TimeTaken` smallint(6) DEFAULT NULL,
  `Wrt_V_SpeedDigits` smallint(6) DEFAULT NULL,
  `Wrt_V_SpeedSums` smallint(6) DEFAULT NULL,
  `Wrt_V_Status` tinyint(4) DEFAULT NULL,
  `Wrt_O_Sums` tinyint(4) DEFAULT NULL,
  `Wrt_O_PCT` float(10,2) DEFAULT NULL,
  `Wrt_O_DPM` float(10,2) DEFAULT NULL,
  `Wrt_O_TimeTaken` smallint(6) DEFAULT NULL,
  `Wrt_O_SpeedDigits` smallint(6) DEFAULT NULL,
  `Wrt_O_SpeedSums` smallint(6) DEFAULT NULL,
  `Wrt_O_Status` tinyint(4) DEFAULT NULL,
  `TimeOfLogout` datetime DEFAULT NULL,
  PRIMARY KEY (`RecNo`)
) ENGINE=InnoDB AUTO_INCREMENT=3 DEFAULT CHARSET=utf8 COLLATE=utf8_unicode_ci;
/*!40101 SET character_set_client = @saved_cs_client */;

--
-- Dumping data for table `mysessdata`
--

LOCK TABLES `mysessdata` WRITE;
/*!40000 ALTER TABLE `mysessdata` DISABLE KEYS */;
INSERT INTO `mysessdata` VALUES (1,'mina12345',1,'1','2018-01-13 16:48:26',4,0,20.00,45.00,16,1,4,80.00,9.35,77,2500,5000,1,4,80.00,11.43,63,2500,2500,1,'2018-01-13 17:48:26'),(2,'mina12345',1,NULL,'0000-00-00 00:00:00',1,20,43.00,18.00,1,NULL,NULL,NULL,NULL,NULL,NULL,NULL,NULL,NULL,NULL,NULL,NULL,NULL,NULL,NULL,NULL);
/*!40000 ALTER TABLE `mysessdata` ENABLE KEYS */;
UNLOCK TABLES;

--
-- Table structure for table `vis_mistakes`
--

DROP TABLE IF EXISTS `vis_mistakes`;
/*!40101 SET @saved_cs_client     = @@character_set_client */;
/*!40101 SET character_set_client = utf8 */;
CREATE TABLE `vis_mistakes` (
  `SNo` bigint(11) NOT NULL AUTO_INCREMENT,
  `UserLogin` varchar(32) COLLATE utf8_unicode_ci NOT NULL,
  `DayID` smallint(11) NOT NULL,
  `Wrt_V_mistakes` varchar(64) COLLATE utf8_unicode_ci DEFAULT NULL,
  `Mtl_V_mistakes` varchar(64) COLLATE utf8_unicode_ci DEFAULT NULL,
  `Mul_V_mistakes` varchar(64) COLLATE utf8_unicode_ci DEFAULT NULL,
  `Div_V_mistakes` varchar(64) COLLATE utf8_unicode_ci DEFAULT NULL,
  PRIMARY KEY (`SNo`)
) ENGINE=InnoDB AUTO_INCREMENT=36 DEFAULT CHARSET=utf8 COLLATE=utf8_unicode_ci;
/*!40101 SET character_set_client = @saved_cs_client */;

--
-- Dumping data for table `vis_mistakes`
--

LOCK TABLES `vis_mistakes` WRITE;
/*!40000 ALTER TABLE `vis_mistakes` DISABLE KEYS */;
INSERT INTO `vis_mistakes` VALUES (1,'mina12345',1,'3,',NULL,NULL,NULL),(2,'ranveer09',1,'4,5,',NULL,NULL,NULL),(35,'mina12345',2,'2,3,',NULL,NULL,NULL);
/*!40000 ALTER TABLE `vis_mistakes` ENABLE KEYS */;
UNLOCK TABLES;
/*!40103 SET TIME_ZONE=@OLD_TIME_ZONE */;

/*!40101 SET SQL_MODE=@OLD_SQL_MODE */;
/*!40014 SET FOREIGN_KEY_CHECKS=@OLD_FOREIGN_KEY_CHECKS */;
/*!40014 SET UNIQUE_CHECKS=@OLD_UNIQUE_CHECKS */;
/*!40101 SET CHARACTER_SET_CLIENT=@OLD_CHARACTER_SET_CLIENT */;
/*!40101 SET CHARACTER_SET_RESULTS=@OLD_CHARACTER_SET_RESULTS */;
/*!40101 SET COLLATION_CONNECTION=@OLD_COLLATION_CONNECTION */;
/*!40111 SET SQL_NOTES=@OLD_SQL_NOTES */;

-- Dump completed on 2018-07-24 12:27:22

Strangely this very code works just great on my old machine where the mysql version is 5.6 php is 7.0.27 and almost the same apache version. It simply does not display or log any errors. I am totally stumped.

Gurus Please help !!

Thanks all !

Link to comment
Share on other sites

1) set php's error_reporting to E_ALL. it is not set to report exceptions and fatal runtime errors, you won't see anything for these type of errors.

2) on the old machine, what 'engine' were the tables using, InnoDB or MyISAM? if they were using MyISAM, then the various commit statements where having no affect and the queries were being executed in the order they are in the php code.

3) the usage of the various commit statements are causing the INSERT and UPDATE queries to not actually be executed until you call the ->commit() method. for prepared queries, i don't know what value the ->execute() calls return for INSERT/UPDATE queries since they are actually being executed later.

4) for the SELECT/INSERT/UPDATE queries for the vis_mistakes table. you can use one INSERT ... ON DUPLICATE KEY UPDATE ... query. if this is the reason you think you need to use the various commit statements, eliminate them and use this one query.

5) the 'output' you have posted doesn't seem to exactly match the posted code and it includes the UPDATE mysessda ... sql which should not be output if the code is really stopping, skipping conditional logic, or transferring execution to any exception handler/php.

6) speaking of an exception handler, since your code is throwing its own exceptions, do you have a custom exception handler and if so, what does it do for exception types that it does not handle, such as mysqli exceptions?

Link to comment
Share on other sites

Hi Mac_gyver !

Thanks for the response !

1.  PHP error reporting is already set to E_ALL.

2.  The tables use InnoDB in both the machines. In fact the DB I have provided is a subset of the same DB in the old or new machine.

3. Correct. In fact the code does not reach the point where the commit is executed. However as you can see I used echo along to check the place where the mysql simply disappears. As indicated by the commented astrix (*) in the code, the code fails at the point immediately after the echoed query ( commented out in my code above) 

if($stmt->executed()) fails and the command 

echo "Generating Query";

is never reached. nor does it generate the subsequent echo in the else part  of this block !!! So what's happening here !!??

4. This one I am not sure I understand what you mean since I am not aware of the On DUPLICATE KEY UPDATE bit. But I will try and explain why what I am doing.

As is seen, the code traverses this block for actually 4 times for 4 cases that occur serially at 4 different points of time. So Wrt_V_mistakes is always inserted and for the other 3 the table needs to be updated.

5. Correct, the posted output focuses on the queries. There is a lot of excess data but the data needed for the queries is available. The output shows RED ( in color)  NULLs which should have numeric data if the query was successfully run. 

6. I have a very simple exception handler that just gives a generic error message for development. I will check on this and revert soon. 

Thanks loads ! 

Ok so here is my handler 

set_exception_handler('exception_handler'); 
set_exception_handler('exception_handler'); 

function exception_handler($e) { 
 
    // public message 
    echo "Something went wrong.\n"; 

} 

I guess the error message that the exception throw is being ignored. Just the same message would also be good to indicate that an exception did occur. But in this case even this message does not show up. 

So i am totally lost as is the query output !?

Thanks you !

 

 

 

 

 

 

Link to comment
Share on other sites

Quote

1.  PHP error reporting is already set to E_ALL.

do you know that for a FACT, by actually displaying the current value that php is using? the symptom of your code not producing output past a point, is usually due to a fatal runtime error or an exception that isn't being reported.

Quote

6. I have a very simple exception handler that just gives a generic error message for development. I will check on this and revert soon. 

depending on the context where the code is at, the error message could be inside of some html where it won't be rendered and displayed in the browser. if so, check what the 'view source' of the page shows.

also, your code setting the mysqli driver error mode is using both procedural and oop notation. while it is unlikely that this is preventing those statements from actually setting the error mode, just use one set of statements. the procedural is the simpler of the two.

Link to comment
Share on other sites

Thank you Mac_gyver !! 

Quote

do you know that for a FACT,  !!

Well it was there for a fact but it was like this 

Quote

error_reporting('E_ALL');

The quotes around E_ALL were screwing it up. I have been at it for almost a week. Can't thank you enough. ?

I am also getting a CSP policy violation error because of the following bit of code that controls the flash movie and is inline as 

	<script language="javascript">
		if (AC_FL_RunContent == 0) {
			alert("This page requires AC_RunActiveContent.js.");
		} else {
		
			AC_FL_RunContent(
				'codebase', 'http://download.macromedia.com/pub/shockwave/cabs/flash/swflash.cab#version=9,0,0,0',
				'width', '725',
				'height', '578',
				'src', 'moveit/glossy',
				'quality', 'high',
				'pluginspage', 'http://www.macromedia.com/go/getflashplayer',
				'align', 'middle',
				'play', 'true',
				'loop', 'true',
				'scale', 'showall',
				'wmode', 'window',
				'devicefont', 'false',
				'id', 'moveit/glossy',
				'bgcolor', '#ffffff',
				'name', 'moveit/glossy',
				'menu', 'true',
				'allowFullScreen', 'false',
				'allowScriptAccess','sameDomain',
				'movie', 'moveit/glossy',
				'FlashVars', 'myVar1=<?php echo $myVar1;?>&myVar2=<?php echo $myVar2;?>',
				'salign', ''
				); //end AC code
		}
	</script>

I would be so happy if you can tell me how to convert this into an external .js file and then invoke it from the code. I believe I have tried this earlier without success and also posted a question on the forum for the same. 

Once again thanks a ton Mac_gyver for the help !

Link to comment
Share on other sites

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.