การเชื่อมต่อ SQL database กับ Web server ซึ่งมันขึ้น Error Warning: odbc_exec() [function.odbc-exec]:
Warning: odbc_exec() [function.odbc-exec]: SQL error: [Microsoft][ODBC SQL Server Driver][SQL Server]Conversion failed when converting datetime from character string., SQL state 22008 in SQLExecDirect in C:\Inetpub\wwwroot\lib\dbms.inc.php on line 33
***code***
<?php
if(!defined('DBMS_DIR')){
define('DBMS_DIR',dirname(__FILE__));
}
class dbms {
var $conn;
var $add_fields_list;
var $fields_list;
function dbms(){
}
function db_con($dns,$user,$passwd){
$this->conn=odbc_connect($dns ,$user, $passwd);
if(!$this->conn){
exit("Data base is not connect.");
}/*else{
echo "yes";
}*/
//$cs1 = "SET NAMES 'tis620'";
//$this->db_exec($cs1);
/*$cs1 = "SET character_set_results=tis620";
$this->db_exec($cs1);
$cs2 = "SET character_set_client = tis620";
$this->db_exec($cs2);
$cs3 = "SET character_set_connection = tis620";
$this->db_exec($cs3);*/
}
function db_exec($sql){
$result=odbc_exec($this->conn,$sql);
return $result;
}
function prepare_addrecord(){
$this->add_fields_list = array();
$this->fields_list = array();
}
function append_field($fieldname , $value){
$this->add_fields_list[] = array('name'=>$fieldname , 'value'=>$value);
$this->fields_list[$fieldname] = $value;
}
function get_whereSql(){
$tb_cols = $this->fields_list;
$i=0;
$whereSql="";
foreach( $this->fields_list as $key=>$value ){
if($i > 0){
$whereSql.=" and ";
}
if(isset($tb_cols[$key])){
$whereSql.=$key."='".($value)."'";
$i++;
}
}
return $whereSql;
}
function get_setSql(){
$tb_cols = $this->fields_list;
$i=0;
$whereSql="";
foreach( $this->fields_list as $key=>$value ){
if($i > 0){
$whereSql.=" , ";
}
if(isset($tb_cols[$key])){
$whereSql.=$key."='".($value)."'";
$i++;
}
}
return $whereSql;
}
function updata_data($tbname,$field="",$value=""){
$sql="UPDATE ".$tbname." set ".$this->get_setSql()." where ".$field."='".$value."'";
$result=$this->db_exec($sql);
return $result;
}
function getData($sql=""){
$result=$this->db_exec($sql);
if($result){
$output=array();
while($row= (odbc_fetch_array($result))){
$output[] = $row;
}
return $output;
}
}
function fetch2DArray($res){
$i = 0;
$j = 0;
$toReturn = "";
while(odbc_fetch_row($res))
{
for ($j = 1; $j <= odbc_num_fields($res); $j++)
{
$field_name = odbc_field_name($res, $j);
$ar[$field_name] = odbc_result($res, $field_name);
}
$toReturn[$i] = $ar;
$i++;
}
return $toReturn;
}
function addLog($page="",$process=""){
if(isset($_SESSION['user_n'])){
//echo $page.",".$process.",".$_SESSION['user_n']."<br>";
$sql="INSERT INTO logfile ( log_page, log_process, log_date, log_user) VALUES"
." ( '".$page."', '".$process."', '".date("Y-m-d")."', '".$_SESSION['user_n']."')";
$result=$this->db_exec($sql);
}
}
function count_row($tbn=""){
$sql="select count(*) as count from ".$tbn;
$data=$this->getData($sql);
return $data[0]['count'];
}
}
?>
ช่วยผมหน่อยครับแก้ยังงัยก็ไม่หายTag : PHP, Ms SQL Server 2005
Date :
2010-07-29 19:23:37
By :
kitnueng
View :
1600
Reply :
3
ขอขอบคุณมากนะครับสำหรับคำตอบ
ถ้าผมไม่ใช้ส่วนที่บอกมาละครับตามด้านล่างมันจะใช้ได้มัย
***code***
<?php
if(!defined('DBMS_DIR')){
define('DBMS_DIR',dirname(__FILE__));
}
class dbms {
var $conn;
var $add_fields_list;
var $fields_list;
function dbms(){
}
function db_con($dns,$user,$passwd){
$this->conn=odbc_connect($dns ,$user, $passwd);
if(!$this->conn){
exit("Data base is not connect.");
}
function db_exec($sql){
$result=odbc_exec($this->conn,$sql);
return $result;
}
function prepare_addrecord(){
$this->add_fields_list = array();
$this->fields_list = array();
}
function append_field($fieldname , $value){
$this->add_fields_list[] = array('name'=>$fieldname , 'value'=>$value);
$this->fields_list[$fieldname] = $value;
}
function get_whereSql(){
$tb_cols = $this->fields_list;
$i=0;
$whereSql="";
foreach( $this->fields_list as $key=>$value ){
if($i > 0){
$whereSql.=" and ";
}
if(isset($tb_cols[$key])){
$whereSql.=$key."='".($value)."'";
$i++;
}
}
return $whereSql;
}
function get_setSql(){
$tb_cols = $this->fields_list;
$i=0;
$whereSql="";
foreach( $this->fields_list as $key=>$value ){
if($i > 0){
$whereSql.=" , ";
}
if(isset($tb_cols[$key])){
$whereSql.=$key."='".($value)."'";
$i++;
}
}
return $whereSql;
}
function updata_data($tbname,$field="",$value=""){
$sql="UPDATE ".$tbname." set ".$this->get_setSql()." where ".$field."='".$value."'";
$result=$this->db_exec($sql);
return $result;
}
function getData($sql=""){
$result=$this->db_exec($sql);
if($result){
$output=array();
while($row= (odbc_fetch_array($result))){
$output[] = $row;
}
return $output;
}
}
function fetch2DArray($res){
$i = 0;
$j = 0;
$toReturn = "";
while(odbc_fetch_row($res))
{
for ($j = 1; $j <= odbc_num_fields($res); $j++)
{
$field_name = odbc_field_name($res, $j);
$ar[$field_name] = odbc_result($res, $field_name);
}
$toReturn[$i] = $ar;
$i++;
}
return $toReturn;
}
function addLog($page="",$process=""){
if(isset($_SESSION['user_n'])){
//echo $page.",".$process.",".$_SESSION['user_n']."<br>";
$sql="INSERT INTO logfile ( log_page, log_process, log_date, log_user) VALUES"
." ( '".$page."', '".$process."', '".date("Y-m-d")."', '".$_SESSION['user_n']."')";
$result=$this->db_exec($sql);
}
}
function count_row($tbn=""){
$sql="select count(*) as count from ".$tbn;
$data=$this->getData($sql);
return $data[0]['count'];
}
}
?>
Date :
2010-07-30 14:12:19
By :
kitnueng
ลง Driver SQL Server ยังครับ อิอิเกี่ยวไหม
Date :
2010-07-30 14:40:30
By :
50121680
Load balance : Server 02