/    Sign up×
Community /Pin to ProfileBookmark

Which Error Code To Use When And Where ?

Folks,

Can you clear some confusions for me ?
Thanks!

On these following 2, which one’s error lines are incorrect and why ?

1

““
mysqli_report(MYSQLI_REPORT_ERROR|MYSQLI_REPORT_STRICT);

$conn = mysqli_connect(“localhost”,”root”,””,”buzz”); //mysqli_connect(“server”,”user”,”password”,”db”);

$input_1 = ‘mogambo’; //username.
$input_2 = ‘[email protected]’; //email.
$input_3 = ‘0’; //id.

$sql = “UPDATE users SET username=?,email=? WHERE id=?”;

if(!$stmt = mysqli_prepare($conn,$sql))
{
echo ‘Mysqli Stmt Error: ‘ .mysqli_stmt_error();
echo ‘<br>’;
echo ‘Mysqli Stmt Error No: ‘ .mysqli_stmt_errno();
}
““

2

““
mysqli_report(MYSQLI_REPORT_ERROR|MYSQLI_REPORT_STRICT);

$conn = mysqli_connect(“localhost”,”root”,””,”buzz”); //mysqli_connect(“server”,”user”,”password”,”db”);

$input_1 = ‘mogambo’; //username.
$input_2 = ‘[email protected]’; //email.
$input_3 = ‘0’; //id.

$sql = “UPDATE users SET username=?,email=? WHERE id=?”;

if(!$stmt = mysqli_prepare($conn,$sql))
{
echo ‘Mysqli Error: ‘ .mysqli_error();
echo ‘<br>’;
echo ‘Mysqli Error No: ‘ .mysqli_errno();
}
““

Can you spot the difference between the 2 error codes ?

to post a comment
PHP

10 Comments(s)

Copy linkTweet thisAlerts:
@novice2022authorFeb 10.2023 — Folks,

Here are some more that need clearing ....

On these following 2, which one's error lines are incorrect and why ?

3

mysqli_report(MYSQLI_REPORT_ERROR|MYSQLI_REPORT_STRICT);

$conn = mysqli_connect("localhost","root","","buzz"); //mysqli_connect("server","user","password","db");

$input_1 = 'mogambo'; //username.
$input_2 = '[email protected]'; //email.
$input_3 = '0'; //id.

$stmt = mysqli_stmt_init($conn);
$sql = "UPDATE users SET username=?,email=? WHERE id=?";

if(!mysqli_stmt_prepare($stmt,$sql))
{
echo 'Mysqli Stmt Error: ' .mysqli_stmt_error();
echo '<br>';
echo 'Mysqli Stmt Error No: ' .mysqli_stmt_errno();
}


4

mysqli_report(MYSQLI_REPORT_ERROR|MYSQLI_REPORT_STRICT);

$conn = mysqli_connect("localhost","root","","buzz"); //mysqli_connect("server","user","password","db");

$input_1 = 'mogambo'; //username.
$input_2 = '[email protected]'; //email.
$input_3 = '0'; //id.

$stmt = mysqli_stmt_init($conn);
$sql = "UPDATE users SET username=?,email=? WHERE id=?";

if(!mysqli_stmt_prepare($stmt,$sql))
{
echo 'Mysqli Error: ' .mysqli_error();
echo '<br>';
echo 'Mysqli Error No: ' .mysqli_errno();
}
Copy linkTweet thisAlerts:
@ginerjmFeb 10.2023 — I think the manual is pretty clear on the use of the proper function.
Copy linkTweet thisAlerts:
@novice2022authorFeb 10.2023 — Folks,

Which of you have read the followings ?

I read about 3-4 yrs ago and forgotten what I learnt and so re-reading & re-learning:

Mysqli Error Reporting

https://phpdelusions.net/mysqli/error_reporting

https://phpdelusions.net/mysqli

Basic Error Reporting

https://phpdelusions.net/articles/error_reporting
Copy linkTweet thisAlerts:
@novice2022authorFeb 10.2023 — @ginerjm#1650552

Oh! Is that so ?

Anyway, have you read the above-mentioned articles ever ? (Not expecting any haughty replies!). Lol!
Copy linkTweet thisAlerts:
@ginerjmFeb 10.2023 — No I haven't read those articles since I choose to use PDO which I and many others believe to be the easier interface to use.
Copy linkTweet thisAlerts:
@novice2022authorFeb 13.2023 — @Nogdog

Care to chime in ?

Thanks.
Copy linkTweet thisAlerts:
@NogDogFeb 13.2023 — None of them are correct, since you have exceptions turned on via mysqli_report(MYSQLI_REPORT_ERROR|MYSQLI_REPORT_STRICT); (which is a good thing, IMHO); so you'll never hit your error outputs if there is a MySQLi error. You would need to use try/catch blocks as I suggested in one of your several related threads.
Copy linkTweet thisAlerts:
@novice2022authorFeb 13.2023 — @NogDog#1650619

Ok. Based on tutorial mentioned in links mentioned above, it seems I shouldnot check for execution errors if I have:

mysqli_report(MYSQLI_REPORT_ERROR|MYSQLI_REPORT_STRICT);

But let us assume I did not have that line. Then, which of my above code I should stick to ?

Thanks
Copy linkTweet thisAlerts:
@novice2022authorFeb 13.2023 — @NogDog


Just finished reading these and I think you would benefit from them. A lot to take:

https://phpdelusions.net/mysqli

https://phpdelusions.net/mysqli/error_reporting

https://phpdelusions.net/error_reporting

I can guarantee you NogDog, you won't regret reading all the tutorial links found on those 3 links and would thank me later. Written by username Your Common Sense from StackOverFlow.

Few things I did not understand in the tutorial and so I might pester you about them in new threads.

I think these links will teach you somethings good. Let me know which ones you found helpful:

https://phpdelusions.net/mysqli/obscure_features

https://phpdelusions.net/mysqli/simple

NogDog, can you remember once I asked you, maybe under another username, about 2yrs ago how to get php auto write prepared statement lines based on variables who's numbers I do not know would be in the preps stmts and you suggested some function but it was not perfect and I came across a stumbling block and halted the project ?

(I will see another day, if I can find that thread to jog your memory). Well today, I came across this tutorial that gave me the function I was looking for. Here it is:

https://phpdelusions.net/mysqli_examples/insert

No, the function is "Helper Function" to create prep stmts on auto. Do checkout the link, when you got time as I may bug you another day about the subject when I come across issues when experimenting with the code.

Do not forget to answer my previous post.

Thanks
Copy linkTweet thisAlerts:
@NogDogFeb 13.2023 — > @novice2022#1650624 Do not forget to answer my previous post.

Nope, I'm not here to review every line of code you write.

> you won't regret reading all the tutorial links found on those 3 links

I have zero interest in mysqli stuff. I use PDO every day with a PostgreSQL database for a high-volume, high-reliability application. Even if we decided we wanted to switch to MySQL for some reason, I'd still use PDO.
×

Success!

Help @novice2022 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 4.23,
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: @Yussuf4331,
tipped: article
amount: 1000 SATS,

tipper: @darkwebsites540,
tipped: article
amount: 10 SATS,

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