Kaz3367 Posted November 13, 2019 Share Posted November 13, 2019 Hello guys. Im not familiar with PHP but I was asked to convert our Homepage which uses a Database to store tickets from 5.x to 7.3.9 . Now I get this error: I'd appreaciate any help from you guys, tia. :) Quote Link to comment Share on other sites More sharing options...
Kaz3367 Posted November 13, 2019 Author Share Posted November 13, 2019 I wanted it to return me a string of the error if there's one - how can I adjust it.. Im kinda lost. Quote Link to comment Share on other sites More sharing options...
Barand Posted November 13, 2019 Share Posted November 13, 2019 There are examples here Quote Link to comment Share on other sites More sharing options...
Kaz3367 Posted November 13, 2019 Author Share Posted November 13, 2019 (edited) 45 minutes ago, Barand said: There are examples here If I were to remove the or die function - it would be able to run on 7. right? While Im thinking of how to implement the stuff you just sent. Edited November 13, 2019 by Kaz3367 Quote Link to comment Share on other sites More sharing options...
chhorn Posted November 13, 2019 Share Posted November 13, 2019 (edited) As to the manual, "die" is an alias of "exit" which is a function, and there are examples in the manual which you should try on a standalone script first, so you learn how to call functions with the appropriate syntax. https://www.php.net/manual/en/function.exit.php Also i would recommend to not just randomly copy and paste function signatures into production code and hoping that they work as you expect, but actually learn how PHP works and what syntax is needed from the examples. Edited November 13, 2019 by chhorn 1 Quote Link to comment Share on other sites More sharing options...
mac_gyver Posted November 13, 2019 Share Posted November 13, 2019 3 hours ago, Kaz3367 said: I wanted it to return me a string of the error if there's one if you use exceptions for database statement errors and in most cases let php catch and handle the exception, php will use its error related settings to control what happens with the actual error information (database errors will 'automatically' get displayed/logged the same as php errors.) you will be able eliminate the existing error handling, rather than to convert it. to enable exceptions for errors for 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); now the bad news, it is not enough to just update statements in old code, as one of the things that was removed in php5.4, magic_quotes, eliminated some protection that php provided against sql special characters in external string data from breaking the sql query syntax (which is how sql injection is accomplished.) if your code does not have specific protection for all external/unknown data, and for all the different data types, being put into sql queries, you will need to add it. the simplest, universal way of doing this is to use prepared queries, provided that you switch to use the simpler PDO extension. the prepared query interface for the mysqli extension is overly complicated and inconsistent 1 Quote Link to comment Share on other sites More sharing options...
Kaz3367 Posted November 15, 2019 Author Share Posted November 15, 2019 On 11/13/2019 at 6:16 PM, mac_gyver said: if you use exceptions for database statement errors and in most cases let php catch and handle the exception, php will use its error related settings to control what happens with the actual error information (database errors will 'automatically' get displayed/logged the same as php errors.) you will be able eliminate the existing error handling, rather than to convert it. to enable exceptions for errors for 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); now the bad news, it is not enough to just update statements in old code, as one of the things that was removed in php5.4, magic_quotes, eliminated some protection that php provided against sql special characters in external string data from breaking the sql query syntax (which is how sql injection is accomplished.) if your code does not have specific protection for all external/unknown data, and for all the different data types, being put into sql queries, you will need to add it. the simplest, universal way of doing this is to use prepared queries, provided that you switch to use the simpler PDO extension. the prepared query interface for the mysqli extension is overly complicated and inconsistent Thanks a lot for your indepth answer. I will try to get more into this matter then. Also another question, we used an excel export code, now that I converted most of the code I came along this following part of code which does no longer exist in PHP 7. I searched for alternatives and I am not sure how to implement them in this specific example, I hope im not asking too much but Im kinda lost.. mysql_field_name Tia Quote Link to comment Share on other sites More sharing options...
Barand Posted November 15, 2019 Share Posted November 15, 2019 If your problem is how to output tab separated data with column names /* SAMPLE DATA +-------+-------+---------+------------+ | empid | fname | lname | dob | +-------+-------+---------+------------+ | 1 | Peter | Smith | 1985-01-26 | | 2 | Paul | Hartley | 1973-12-02 | | 3 | Mary | Baker | 1980-04-11 | | 4 | Jane | Doe | 1990-11-28 | +-------+-------+---------+------------+ */ $res = $db->query("SELECT empid , fname , lname , dob FROM employee; "); echo '<pre>'; $row = $res->fetch(PDO::FETCH_ASSOC); echo join("\t", array_keys($row)) . "\n"; // headings do { echo join("\t", $row) . "\n"; // data } while ($row = $res->fetch()); echo '</pre>'; Which gives Similarly, if you want to write it to a csv file for export to Excel, then $res = $db->query("SELECT empid , fname , lname , dob FROM employee; "); $fp = fopen('AAA.csv', 'w'); $row = $res->fetch(PDO::FETCH_ASSOC); fputcsv($fp, array_keys($row), "\t"); // headings do { fputcsv($fp, $row, "\t"); // data } while ($row = $res->fetch()); 1 Quote Link to comment Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.