הרשם שאלות ותשובות רשימת חברים לוח שנה חיפוש הודעות מהיום סמן פורומים כנקראו

   
|!|

השב
 
כלים לאשכול תצורת הצגה
ישן 06-03-08, 12:41   # 1
ahoy
חבר בקהילה
 
מיני פרופיל
תאריך הצטרפות: Mar 2007
הודעות: 340
שלח הודעה באמצעות MSN אל ahoy

ahoy לא מחובר  

כבר כתבתי סקריפט PHP שעושה המרה בעזרת ICONV (אחרי ש-html_entity_decode גם לא עבד) באותה הטבלה וזה לא עבד:

$fieldsquery = "select * from ".$db.".".$table."";
$fields_result = mysql_query($fieldsquery);
$num_fields = mysql_num_fields($fields_result);

for ($j = 0; $j < $num_fields ; $j++)
{

$column = mysql_field_name($fields_result, $j);

$query = "select ".$column." from ".$db.".".$table."";
$result = mysql_query($query);
$num_result = mysql_num_rows($result);

for ($i = 0; $i < $num_result; $i++)
{
$thing1 = mysql_result($result,$i);

echo $thing1.'<br>';

//$thing2 = html_entity_decode($thing1, ENT_QUOTES, 'utf-8');

$things2 = iconv("windows-1255", "UTF-8", $thing1);

echo '<br>'.$thing2.'<br>';

$queryreplace = "update ".$db.".".$table." set ".$column." = '".$thing2."' where ".$column." = '".$thing1."'";
echo $queryreplace."<br>";
mysql_query($queryreplace);
}


... מה המשמעות של SET NAMES לקידוד? היכן זה אמרו להכנס?
  Reply With Quote
ישן 06-03-08, 15:20   # 2
בניה
משתמש - היכל התהילה
 
מיני פרופיל
תאריך הצטרפות: Oct 2005
מיקום: נחושה
הודעות: 3,434

בניה לא מחובר  

ה SET NAMES זו שאילתה שקובעת את הקידוד של החיבור שלך עם המסד נתונים.
אם הקידוד של החיבור הוא latin1 ואתה מנסה להעביר UTF8 או ההפך אתה עלול לקבל סימני שאלה/גי'בריש.

וגם אתה חייב שהcollation במסד יוגדר כמו שצריך לפני שאתה מכניס אליו מידע בUTF8.

קוד שעבד לי:

PHP קוד:
<?php
error_reporting
(E_ALL);

set_time_limit(600);

    function 
sql_query($query)
    {
        global 
$con;
        
$trace debug_backtrace();

        
$file = &$trace[0]['file'];
        
$line = &$trace[0]['line'];

        
$res mysql_query($query$con);
        if(!
$res)
             die(
"\r\nSQL ERROR: [".$query."|".mysql_error()."] in "$file ." AT ".$line);
        else
            return 
$res;
    }

    function 
convert($str) {

        return 
iconv("windows-1255""UTF-8"$str);

    }

    function 
sql_escape($str){
        global 
$con;
        return 
mysql_real_escape_string($str$con);
    }

$db 'conv';

$table 'lalal';

$con mysql_connect('localhost''root');

mysql_select_db($db$con);

sql_query("SET NAMES 'hebrew'"$con);

$sql "SELECT * FROM " $db "." $table "";

$res sql_query($sql);

sql_query("SET NAMES 'UTF8'"$con);

$fields false;

$c 0;
$values = array();

$rows_num mysql_num_rows($res);

while(
$row mysql_fetch_assoc($res)) {


    if(
$c == 0) {
        
$sql "INSERT INTO `new_{$table}` (`" implode('`,`'array_keys($row)) . "`) VALUES ";

    }

    
$c++;

    
$row array_map('convert'$row);
    
$row array_map('sql_escape'$row);

    
$values[] = "('" implode("','"$row) . "')";

    if((!
$c%10) || $c == $rows_num) {
        
sql_query($sql implode(','$values));
        
$values = array();
    }
}


echo 
"{$c} rows converted";
?>
(אני צריך אחד גם לעצמי)
  Reply With Quote
השב

חברים פעילים הצופים באשכול זה: 1 (0 חברים ו- 1 אורחים)
 

כלים לאשכול
תצורת הצגה

חוקי פירסום
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is מופעל
סמיילים הם מופעל
[IMG] קוד מופעל
קוד HTML מכובה

קפיצה לפורום


כל הזמנים הם GMT +2. הזמן כעת הוא 00:01.

מופעל באמצעות VBulletin גרסה 3.8.6
כל הזכויות שמורות ©
כל הזכויות שמורות לסולל יבוא ורשתות (1997) בע"מ