Tag: MySQL

2009-04-28

MySQLi: Avoid Explicitly Listing Every Column in bind_result()

by Charles — Categories: PHP — Tags: , , , 1 Comment

Upon being motivated by a “PHP style critique” discussion at the WebDeveloper.com forums, I dug around the manual page for mysqli_stmt::bind_result(), and noticed an interesting suggestion for the use of the call_user_func_array() function in combination with the bind_result() method (see the user note by “hamidhossain”).

The essence of the technique is to use call_user_func_array() to call the bind_param() method, supplying the list of variables to be bound via an array which has its elements defined as references to the actual variables you want bound. In the following example, I’m referencing them to a class variable named $data which is an associative array where the keys are the field names for the database table being operated upon.
(more…)

2008-10-03

UTF8 in PHP and MySQL

by Charles — Categories: PHP — Tags: , , 4 Comments

The intent of this article is to tie together some things I’ve learned to do in order to get my web apps to “play nicely” with the UTF8 character set. Before we go any further, let me state that I do not claim to be an expert on this; the following is simply a collection of things I’ve discovered here and there on the web, and which together seem to help smooth out most of the bumps in the road of using UTF8.

So let’s start with the database itself. To get your varchar and text fields talking UTF8, you should assign both the character set and a corresponding collation. (See the MySQL manual section on character sets and collations to see the differences between the various collation types.) You can assign this stuff at the field level should you desire, but generally I just assign it at the table level:

(more…)

© 2012 PHP Musings All rights reserved - Wallow theme v0.46.4 by ([][]) TwoBeers - Powered by WordPress - Have fun!