Re: Re: 0x9f54

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



    OK, I've spent five minutes to try to understand what you're doing. 
There're something I don't understand:
1. You use dbase_open("/home/bt/canton.DBF",0);
which seems that you open a database file directly.
Well, I don't do like this.  I use mysql_connect("localhost",
"username", "some_password") but I suppose this isn't important or relevant.
2. You seem to read something from one table and reinject them into some
other table.  Am I correct?

    Anyway, since I don't have your data, I can't see or guess where the
problem is.

    You know what, when you try to ask for help, it's always nice to
just give the reduced and minimalistic test case.  I mean, if you're
launching a big trunk of code to others' face and hope they help, don't
be disappointed that they can't help.  We're all volunteers and we would
just spend as less time as possible to help others.  We're not supposed
to spend a lot of time to solve your problem.

    So, tell us what didn't work.  Make up a reduced case, eg reduce the
table to just the problem column, show us the problem query.  You know,
on doing a reduced case, sometimes you are able to spot the problem
yourself immediately.  This is also the way you should learn if you're
to become a real programmer: strict and organized.

    I've told you in a previous post but perhaps you didn't catch it. 
Try your query in MySQL Query Browser and see if you've got the same
problem first.

    HTH

Man-wai Chang wrote:
>> Well, show us a part of your code. Do var_dump($value) before you
>> enter it into the database, and see if it still says 0x9f54.
>>     
>
> The error:
>
> string(2) ""
> Duplicate entry '' for key 1
>
>   
> ------------------------------------------------------------------------
>
> <?
> class MYSQL {
> 	private $fhandle;
> 	var $row;
> 	function MYSQL($host,$db,$usr,$pwd) {
> 		$this->fhandle=new mysqli($host,$usr,$pwd,$db)
> 			or die(mysqli_error($this->fhandle));
> 		$this->query("set names 'big5'");
> 	}
> 	function query($sql_str) {
> 		$this->row=mysqli_query($this->fhandle, $sql_str) or die(mysqli_error($this->fhandle));
> 	}
> 	function affected_rows() {
> 		return mysqli_affected_rows($this->row);
> 	}
> 	function num_rows() {
> 		return mysqli_num_rows($this->row);
> 	}
> 	function fetch_assoc() {
> 		return mysqli_fetch_assoc($this->row);
> 	}
> 	function __destruct() {
> 		mysqli_close($this->fhandle);
> 	}
> 	function begin_tran() {
> 		mysqli_autocommit($this->fhandle, FALSE);
> 	}
> 	function commit() {
> 		mysqli_commit($this->fhandle);
> 		mysqli_autocommit($this->fhandle, TRUE);
> 	}
> 	function rollback() {
> 		mysqli_rollback($this->fhandle);
> 		mysqli_autocommit($this->fhandle, TRUE);
> 	}
> }
>
> function showcode($cChar) {
> 	return "[".dechex(ord(substr($cChar,0,1))).".".dechex(ord(substr($cChar,1,1)))."]";
> }
>
>
> $target=new MYSQL("localhost","testing","root","testing");
>
> $fhandle=dbase_open("/home/bt/canton.DBF",0);
> if ($fhandle) {
> 	$reccount=dbase_numrecords($fhandle);
> 	echo "input count: ".$reccount."\n";
> 	$target->query("show tables like 'canton';");
> 	if ($target->num_rows()>0)
> 		$target->query("drop table canton");
> 	$target->query(
> 		"create table canton ("
> 		. " big5 char(2) not null,"
> 		. " thekey char(6),"
> 		. " canton char(10),"
> 		. " changjei char(10),"
> 		. " touched integer,"
> 		. " primary key (big5)"
> 		. " ) character set big5;"
> 	);
> 	for ($ii=1; $ii<=$reccount; $ii++) {
> 		$row=dbase_get_record_with_names($fhandle,$ii);
> 		$ss=$row['BIG5'];
> 		echo var_dump($ss);
> 		$target->query("select * from canton where big5='".$ss."'");
> 		$yy = $target->num_rows();
> 		if ($yy>0) {
> 			$query="update canton set touched="
> 				. $row["TOUCHED"]
> 				. " where big5='" . $ss . "';";
> 		}
> 		else {
> 			$query="insert into canton ("
> 				. " big5,"
> 				. " thekey,"
> 				. " changjei,"
> 				. " canton,"
> 				. " touched "
> 				. ") values ("
> 				. "'$ss',"
> 				. "'".$row["THEKEY"]."',"
> 				. "'".$row["CHANGJEI"]."',"
> 				. "'".$row["CANTON"]."',"
> 				. $row["TOUCHED"]
> 				. ");";
> 		}
> 		$result=$target->query($query);
> 		if (! $target->row)
> 			echo showcode($ss);
> 	}
> 	$result=$target->query("select count(*) as cnt from canton");
> 	$yy = $target->fetch_assoc();
> 	echo "output count: ".$yy['cnt']."\n";
> 	dbase_close($fhandle);
> }
> ?>
>
>
> ----------
> * Zoner PhotoStudio 8 - Your Photos perfect, shared, organised! www.zoner.com/zps
>   You can download your free version.
>   

-- 
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php


[Index of Archives]     [PHP Home]     [Apache Users]     [PHP on Windows]     [Kernel Newbies]     [PHP Install]     [PHP Classes]     [Pear]     [Postgresql]     [Postgresql PHP]     [PHP on Windows]     [PHP Database Programming]     [PHP SOAP]

  Powered by Linux