/    Sign up×
Community /Pin to ProfileBookmark

Error reporting The Right & Safe Way

Php folks,

I still a beginner. When I get stuck and ask at stackoverflow.com they just tell me too many advanced stuffs and I don;t understand their language level and so I need you people to chime in.
They tell me to write error codes based on these links but I’m still beginner and don’t understand all these error handlers and catchall and throw or whatever the heck they are.
Can you folks be kind enough to checkout these 2 links:

https://codereview.stackexchange.com/questions/234405/php-mysqli-connection-file/243749#243749
https://phpdelusions.net/articles/error_reporting

And once you’ve learnt the advanced way to safely write error reporting and mysqli connection failure error codes from those 2 links then share your finds (code) with us.
They keep telling me to log errors to a file outside the public_html. I don’t know how to do all this stuff. That is why I asking you. To show me a code sample.
I believe the 2 links will be handy for you too. You might learn a thing or 2 about website security. And so, do bother to check the 2 links out. Then ofcourse get back to me with your noted codes. πŸ˜‰
Once you have given me your codes that are bug free, then I go and learn it. First try to understand the lines. Then memorise them.
Even though I am reading the 2 links now, I don’t quite understand what they are teaching as it is adv stuff.

At stackoverflow.com, I’m scared to ask questions on other topics other than error reporting or mysqli connection failure error coding. Because, they always ask me where my error reporting and mysqli conenction codes are and when I show them then they say they told me before to fix them in past threads and I still haven’t. They show irritation.
Problem is, the links they give me is too much over my head and I don;t understand them. Hence, I fail to adapt their adv level way.
So, I think best you adv guys check the links out and note the proper codes the proper way and then share them here with us. That way, beginners like me don’t have to wade through the whole sea just to catch 2 fishes.
No. Not trying to get you to do my dog work but you might learn a thing or 2 from the links yourselves. let me know if you learnt anything new or not. Ok ?

Thanks

https://codereview.stackexchange.com/questions/234405/php-mysqli-connection-file/243749#243749
https://phpdelusions.net/articles/error_reporting

Else, I just stick to my beginner level error reporting and mysqli connection error codes which stackoverflow.com programmers have a problem with …..

conn.php

““
<?php

$server = ‘localhost’;
$db_user = ‘root’;
$db_password = ”;
$db = ‘test’;

mysqli_report(MYSQLI_REPORT_ERROR|MYSQLI_REPORT_STRICT);
$conn = mysqli_connect($server,$db_user,$db_password,$db);
mysqli_set_charset($conn,’utf8mb4′);

if(mysqli_connect_error())
{
echo “Mysqli Connection Error” . mysqli_connect_error();
}
elseif(mysqli_connect_errno())
{
echo “Mysqli Connection Error Number” . mysqli_connect_errno();
}

?>

““

error_reporting.php

““
<?php
ini_set(‘display_errors’,’1′);
ini_set(‘display_startup_errors’,’1′);
ini_set(‘error_reporting’,’E_ALL’);//error_reporting(E_ALL);
?>
““

When I get codes from tutorials or php manual, stackoverflow.com programmers tell me they are outdated. So, where the hell am I supposed to learn the non-outdated way I asked today and they gave me those links. Just have a look at the links, it’s gonna drive you crazy, if you were a beginner!
Pissing me off.

To make things worst, the links are oop. I still at procedural. Don’t know pdo either. I tell stackoverflow.com guys this but they expect me to ditch mysqli and procedural and jump to pdo. I told them today, I ain’t quitting half-way as I don’t want to gain a habit of quitting things half-way. So stubbornly, I am sticking to mysqli until I finished my current project to build a pagination with it.

They hint, the links will teach hack proof. Sort of. This is where our php won’t echo errors to users, who could be a hacker, and give out security info. They say, I shouldn’t manually check for mysqli, prepared statement, connection errors or whatever.

to post a comment
PHP

5 Comments(s) ↴

Copy linkTweet thisAlerts:
@developer_webauthorJul 31.2020 β€”Β For example, look at this:

"Just keep in mind that if your connection code is wrapped in a function, this function's parameters will be shown in the stack trace as well. So, to avoid the credentials leak in this place, either send the credentials into this function in the form of an array or an object, or fetch them inside the function."

https://phpdelusions.net/mysqli/mysqli_connect

Now, what on earth is a stack or a stack trace for that matter ? You see why beginners get put off ?

Plus, I don't even know what an object is. Not at oop yet. Even though I read a few times the differences between procedural style and oop, when they talk about "objects" I just lose my head. Don't understand it atall! For 3.5yrs now. Hence, stick to procedural style and mysqli. Not go to oop or pdo.

And it talks about "wrapper" and "class" which I have no clue what they are.

"In case your code is OOP, you most likely would put it in the constructor of your own database wrapper class. In this case you may want to check whether your class has any of the common mistakes, just in case."

https://phpdelusions.net/mysqli/mysqli_connect
Copy linkTweet thisAlerts:
@daveyerwinJul 31.2020 β€”Β @developer_web#1621584

> @developer_web#1621584 Don't know pdo either

if you are using mysqli and

you intend to run only mysqli

pay no attention to that man

behind the curtain(pdo)

try to learn mysqli instead

I'm just curious,

where do you run your code

on your own computer ?
Copy linkTweet thisAlerts:
@developer_webauthorAug 01.2020 β€”Β @DaveyErwin#1621589

Don't have a website yet. Will hire vps. Use localhost Xampp.

Why ?

Since I take codes from you then make sure my localhost doesn;t get messed-up if your code has any lines meant for the non-localhost server.
Copy linkTweet thisAlerts:
@NogDogAug 01.2020 β€”Β > @developer_web#1621584 To make things worst, the links are oop. I still at procedural. Don't know pdo either.

Maybe spend an afternoon and/or evening here: https://laracasts.com/series/php-for-beginners

Jeffrey explains things in a clear and calm way, and this set of videos includes one on just enough OOP basics to get you ready to use PDO (which starts in the following video). Also, he's a really nice guy. (I met him several years ago at a conference.)
Copy linkTweet thisAlerts:
@developer_webauthorAug 03.2020 β€”Β @NogDog#1621626

Thanks. But isn't laracast framework ? I don't like frameworks and prefer the core php. Frameworks are built by third parties. Commercial companies.

I am sort of a Unixy thingy and not Windows or Microsoft thingy. If you understand what I mean.
Γ—

Success!

Help @developer_web spread the word by sharing this article on Twitter...

Tweet This
Sign in
Forgot password?
Sign in with TwitchSign in with GithubCreate Account
about: ({
version: 0.1.9 β€” BETA 3.29,
whats_new: community page,
up_next: more Davinciβ€’003 tasks,
coming_soon: events calendar,
social: @webDeveloperHQ
});

legal: ({
terms: of use,
privacy: policy
});
changelog: (
version: 0.1.9,
notes: added community page

version: 0.1.8,
notes: added Davinciβ€’003

version: 0.1.7,
notes: upvote answers to bounties

version: 0.1.6,
notes: article editor refresh
)...
recent_tips: (
tipper: @darkwebsites540,
tipped: article
amount: 10 SATS,

tipper: @Samric24,
tipped: article
amount: 1000 SATS,

tipper: Anonymous,
tipped: article
amount: 10 SATS,
)...