#1
  1. No Profile Picture
    Registered User
    Devshed Newbie (0 - 499 posts)

    Join Date
    Jan 2014
    Posts
    2
    Rep Power
    0

    Error inserting values with special characters in mysql


    With this code i pretend to insert values in mysql db...
    The values are something like this:
    S10-Avaliação Final (Portuguese)


    PHP Code:
    <?php 

    class ImportationCommand extends CConsoleCommand
    {
     
        public function 
    run($args)
        {
            
            
    $i=0;
            
    $file_handle fopen(Yii::app()->request->baseUrl."/import/tailoring.csv""r");
            if (
    $file_handle) {
                while ((
    $line fgets($file_handle)) !== false) {
                    
    //$line = str_replace("'","\'",$line);   
                    
    $model = new Tailoring;
                    
    $model->code $line;
                    
    $model->description =$line;
                    if (!
    $model->save()){
                        echo 
    "erro a criar: $line";

                        
    //mysql_real_escape_string(trim($line));
                        //echo $model->getError();
                    
    }else
                        
    $i++;
                }
            }
            else {
                echo 
    "Error: unexpected fgets() fail\n";
            }
            
    fclose($file_handle);
            echo 
    "tailorings criados: $i";
        }
    }
    Can you help me correcting this issue...the values are not inserted in the database....only values without special carachters are inserted...Collation is utf8_general_ci...
  2. #2
  3. --
    Devshed Expert (3500 - 3999 posts)

    Join Date
    Jul 2012
    Posts
    3,959
    Rep Power
    1014
    So what are we supposed to do with this code? It tells us exactly nothing about the database connection and the queries.

    Have you read the manual on how to set the character encoding of the connection? Otherwise, you're probably better off asking this question in a Yii-specific forum.
    The 6 worst sins of securityHow to (properly) access a MySQL database with PHP

    Why can’t I use certain words like "drop" as part of my Security Question answers?
    There are certain words used by hackers to try to gain access to systems and manipulate data; therefore, the following words are restricted: "select," "delete," "update," "insert," "drop" and "null".
  4. #3
  5. No Profile Picture
    Registered User
    Devshed Newbie (0 - 499 posts)

    Join Date
    Jan 2014
    Posts
    2
    Rep Power
    0

    db connection


    PHP Code:
    Thank you very much for the information
    It
    's my first time here and i don't erally know nothing about php and this framework... 

IMN logo majestic logo threadwatch logo seochat tools logo