Unable to trouble shoot can anybody help please. Thanks
Can’t troubleshoot if we don’t see you code.
This error generally means that your query failed due to an sql error or a problem with your database, but you don’t have any error handling for the sql query statement. A less common cause is the misuse of a fetch statement following a query type that doesn’t return data or reusing the variable that is supposed to hold the msyqli_result.
For the first case, you ALWAYS need error handling for database statements that can fail - connection, query, prepare, and executed. The simplest way of doing this, without adding logic at each statement, is to use exceptions for database errors and in most cases let php catch and handle the exception where it will use its error related settings to control what happens with the actual error information (database statement errors will ‘automatically’ get displayed/logged the same as php errors.)
For the second case, this is a programming mistake and it would require seeing all the relevant code to confirm or eliminate this as the reason for the php Warning.
Thanks for reply, I found the mistake, however kindly inform me how to
" to use exceptions for database errors and in most cases let php catch and handle the exception"
Since you are using the mysqli extension, add the following line of code before the point where you make the database connection -
mysqli_report(MYSQLI_REPORT_ERROR | MYSQLI_REPORT_STRICT);
I am making a php script to modify my ipaddress, I can access my data with the following script:-
3 $file = ‘/etc/sysconfig/network-scripts/ifcfg-eth0’;
4 $myfile = fopen($file, “r”) or die(“Unable to open file.”);
5 $test_str = explode("\n", fread($myfile,filesize($file)));
7 $keys1 = preg_grep("/DEVICE/" , $test_str);
This gives the complete line,
but I want the data after =
substr() or explode()
the issue with both is that ifcfg-eth0’ file has multiple lines, so data length would be different for each line.
I want the code to work as follows
if line has say “DEVICE” then extract data after “=” from that line, regardless of length and type of data
file(), foreach, strpos(), explode()
already used file() explode() them see script above, will try out stpros() and foreach thanks