Articles
In this section I will post various articles related to PHP programming.
Related articles:
- Relative and absolute paths, in the file system and on the web server.
- PHP error reporting
- Do you abuse the null coalescing operator (and isset/empty as well)?
- Do you really need to check for both isset() and empty() at the same time?
- What's wrong with popular articles telling you that foo is faster than bar?
- Numerical strings comparison
- MVC in simpler terms or the structure of a modern web-application
- How to get a single player's rank based on the score
- Why should I use prepared statements if escaping is safe?
- Operator precedence or how does 'or die()' work.
- Do generators really reduce the memory usage?
- How to make Stack Overflow a nice place
- How to debug small PHP programs
- Iterating over array getting look-ahead items along
Comments:
Have you written any books on PHP, or recommend any books? Thank you very much, and keep up the fantastic work!
Reply:
Hello Adrian!
No, I didn't write any, but I can recommend PHP&MySQL by Jon Duckett. It's most recent and thorough book on PHP and Mysql which guides you through creation of a full featured web-site.
How come this website isn't accessible from Ukraine? I had to run VPN to enter it.
Please fix it!
I want to update table1 with the result of this test query.
I cannot work out the PDO coding to this.
Can you help me please ?
Rerards David.
Reply:
Hello David!
Surely I can, but I cannot make what do you mean under "update". Most likely you can to it with pure SQL, but I need to know what you want to update and on which condition.
please help me in future too i am a beginner level front end developer
Reply:
You are welcome, feel free to leave a comment if you have a question
i think it worked
array(12) { ["id"]=> string(1) "2" [0]=> string(1) "2" ["ename"]=> string(3) "Ben" [1]=> string(3) "Ben" ["ssn"]=> string(8) "90887798" [2]=> string(8) "90887798" ["dept"]=> string(3) "cse" [3]=> string(3) "cse" ["salary"]=> string(5) "23000" [4]=> string(5) "23000" ["homeaddress"]=> string(26) "gvgjvjv r hhr, rhjbhjbrhj" [5]=> string(26) "gvgjvjv r hhr, rhjbhjbrhj" }
$username = 'Ben'; $dept = 'cse'; $sql ="SELECT * FROM emp_record WHERE ename = ':one' AND dept = ':two' "; $stmt = $conn->prepare($sql); $stmt->execute([":one" => $username,":two" => $dept]); $result = $stmt->fetch() ;
why i am getting $result = false;
Reply:
Hello Brinth!
That's because you put placeholders in quotes. It should be just :name without quotes:
Hello there, might be bit offtopic as its about codeigniter question: as i have read posts that states that codeigniter doesnt officially support prepared statements but rather uses query builder which further does escaping but i have seen many posts stating that only escaping isnt enough for preventing SQL injection
so how can i make sure that of i use query builder i am safe? will Query builder take care of SQL injection prevention when properly used? Thanks ☺
Reply:
Hello Harsh!
The answer is not that easy. On the one hand, escaping alone is not enough. But if you are doing escaping and quiting, then your data is perfectly safe.
Getting back to the Codeigniter, it all depends on the implementation. I assume that it should be quite safe to use the Query builder
Hi. Your website is SUPER usefull, specially in PDO article.
I write this to you for make a idea, can you publish a article with the new function of PHP=> Closure.
Talking about call - bind - bindto - fromCallabe
Thanks :)
Im in stackoverflow and es.stackoverflow
Reply:
Hello Victor!
Could you please provide more details?
Are you asking for the article on the Closures in general or on how to use Closures with PDO? If the latter, please explain what certain scenario you have in mind.
Thank you!