SitePoint Sponsor

User Tag List

Results 1 to 9 of 9
  1. #1
    SitePoint Member
    Join Date
    Nov 2009
    Posts
    2
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    MYSQLI_SET_CHARSET() Not Supported by FatCow.Com

    I have recently started to delve into the SitePoint Build Your Own Database Driven Website book and have discovered that my web host (fatcow.com) has an outdated version of the MYSQLI Client Library (they are running 4.1.11). As such, a fatal error is returned when the function MYSQLI_SET_CHARSET is run:

    Fatal error: Call to undefined function mysqli_set_charset() in /hermes/web03/b535/moo.tstevens/henselphelpsonline/jha/includes/db.inc.php on line 10

    Is there another way to set the default character set to UTF8 than using this function?

  2. #2
    Non-Member
    Join Date
    Oct 2009
    Posts
    1,852
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    sure.
    just execute this query
    Code:
    SET NAMES UTF8

  3. #3
    SitePoint Wizard bronze trophy
    Join Date
    Jul 2008
    Posts
    5,757
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    note the difference between mysql and mysqli functions.

    In any case
    http://dev.mysql.com/doc/refman/4.1/...onnection.html

  4. #4
    SitePoint Member
    Join Date
    Nov 2009
    Posts
    2
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    In Kevin Yank's example for building a joke database, he has an include file called "db.inc.php" and has the following code in it:

    Code:
    if (!mysql_set_charset($link, 'utf8'))
    {
    	$output = 'Unable to set database connection encoding.';
    	include 'output.html.php';
    	exit();
    So could I run the following an achieve the same outcome:

    Code:
    if (!SET NAMES UTF8)
    {
    	$output = 'Unable to set database connection encoding.';
    	include 'output.html.php';
    	exit();

  5. #5
    SitePoint Wizard PHPycho's Avatar
    Join Date
    Dec 2005
    Posts
    1,201
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    The way i deal with charset is as (just a piece of code):
    PHP Code:
    if ( defined('DB_CHARSET') )
        
    $this->charset DB_CHARSET;

    if ( 
    defined('DB_COLLATE') )
        
    $this->collate DB_COLLATE;
    if (
    function_exists('mysql_set_charset')) {
         if(!
    mysql_set_charset($this->charset$this->linkID)){
            
    logMessage('error''Unable to set character set: '.$this->charset);            
            if (
    $this->debug){
                
    $this->displayError('Unable to set character set: %s'$this->charset);
            }
        }
    }else{
        
    $collation_query "SET NAMES '{$this->charset}'";
        if ( !empty(
    $this->collate) )
                    
    $collation_query .= " COLLATE '{$this->collate}'";
        
    $this->doQuery($collation_query);

    in my database wrapper constructor.

  6. #6
    Non-Member
    Join Date
    Oct 2009
    Posts
    1,852
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    oh gosh
    why do you do such weird things?
    why such complicated counstruction for one simple SQL query?
    why raise error instead of using query?

  7. #7
    SitePoint Wizard PHPycho's Avatar
    Join Date
    Dec 2005
    Posts
    1,201
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Quote Originally Posted by Shrapnel_N5 View Post
    oh gosh
    why do you do such weird things?
    why such complicated counstruction for one simple SQL query?
    why raise error instead of using query?
    I don't think this is complicated.
    Generally when database object is created using singleton pattern, the constructor do connect the mysql and selects the db & then set the charset according to the configuration.

    If debug mode is enabled and error occurs then it simply displays the error.

    That's all.

  8. #8
    Non-Member
    Join Date
    Oct 2009
    Posts
    1,852
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    one single line
    PHP Code:
    $this->doQuery("SET NAMES ".DB_CHARSET); 
    is more than enough

    Now I understand why many php apps have size of tens of megabytes zipped.

  9. #9
    SitePoint Wizard PHPycho's Avatar
    Join Date
    Dec 2005
    Posts
    1,201
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Quote Originally Posted by Shrapnel_N5 View Post
    one single line
    PHP Code:
    $this->doQuery("SET NAMES ".DB_CHARSET); 
    is more than enough

    Now I understand why many php apps have size of tens of megabytes zipped.
    OK NP If you want to reduce code why to use wrapper then it too reduces the code & size


Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •