2012-04-26 14 views
1

多くの研究の後にADOBD mssql y free tdsに接続できますが、今は別の問題があります。Activeレコードを使用しようとしましたが、できません。私はそれがなかった通常の挿入のコメントを外し、それがアクティブレコードADODB PHP MS-SQLサーバーSAVE()の問題

This is the response: 

> (mssql): select top 3 * from banks order by 1 desc 

Array 
(
    [0] => Array 
     (
      [0] => 26 
      [1] => Banco 10:54:29 26/04/2012  
     ) 

    [1] => Array 
     (
      [0] => 25 
      [1] => Banco 10:54:18 26/04/2012  
     ) 

    [2] => Array 
     (
      [0] => 23 
      [1] => BANSEFI 2      
     ) 

) 

(mssql): select c.name,t.name,c.length,c.isnullable, c.status, (case when c.xusertype=61 then 0 else c.xprec end), (case when c.xusertype=61 then 0 else c.xscale end) from syscolumns c join systypes t on t.xusertype=c.xusertype join sysobjects o on o.id=c.id where o.name='banks' (mssql): select distinct k.column_name,ordinal_position from information_schema.key_column_usage k, information_schema.table_constraints tc where tc.constraint_name = k.constraint_name and tc.constraint_type = 'PRIMARY KEY' and k.table_name = 'banks' and k.table_catalog like 'tss_dev%' order by ordinal_position (mssql): INSERT INTO banks(id_bank,desc_bank) VALUES (?,?) [ (0=>null) (1=>'Banco 11:05:42 26/04/2012') ] sp_executesql N'INSERT INTO banks(id_bank,desc_bank) VALUES (@P0,@P1); select SCOPE_IDENTITY()',N'@P0 CHAR, @P1 NVARCHAR(25)',@P0=NULL, @P1=N'Banco 11:05:42 26/04/2012' 
(mssql): select SCOPE_IDENTITY() (mssql): select max(id_bank) from banks 
Guarde: el id = '26 - Banco 11:05:42 26/04/2012 11:05:42 26/04/2012' 
Error= (mssql): select top 3 * from banks order by 1 desc 

Array 
(
    [0] => Array 
     (
      [0] => 26 
      [1] => Banco 10:54:29 26/04/2012  
     ) 

    [1] => Array 
     (
      [0] => 25 
      [1] => Banco 10:54:18 26/04/2012  
     ) 

    [2] => Array 
     (
      [0] => 23 
      [1] => BANSEFI 2      
     ) 

) 


Acabe: 11:05:42 26/04/2012 

ないですし、場合

include('adodb/adodb.inc.php'); 
include('adodb/adodb-active-record.inc.php'); 

$db = ADONewConnection('mssql'); # eg 'mysql' or 'postgres' 
$db->Connect('*********', "*********", '**********', "**********"); 
ADOdb_Active_Record::SetDatabaseAdapter($db); 
ADODB_Active_Record::$_changeNames = FALSE; 
$db->debug = true; 
#the following example use a table that was created with this statement 
$rs = $db->Execute("select top 3 * from banks order by 1 desc"); 
print "<pre>"; 
print_r($rs->GetRows()); 
print "</pre>"; 
#create an empty class to work with our new table 
class banks extends ADOdb_Active_Record {} $banks2 = new banks(); 
$banks2->desc_bank = 'Banco '.date("H:i:s d/m/Y"); 
$banks2->save(); // this save() will fail on INSERT as favorite_color is a must fill... 

echo "<br/> Guarde: el id = '$banks2->id_bank - $banks2->desc_bank ".date("H:i:s d/m/Y")."'"; 
$ok = $banks2->Save(); 

if (!$ok) $err = $banks2->ErrorMsg(); 
echo "<br> Error= $err"; 
unset($banks); 
// $rs = $db->Execute("insert into banks values('".'Banco '.date("H:i:s d/m/Y")."')"); 
$rs = $db->Execute("select top 3 * from banks order by 1 desc"); 
print "<pre>"; 
    print_r($rs->GetRows()); 
print "</pre>"; 
echo "<br/> Acabe: ".date("H:i:s d/m/Y"); 

が、これがある:それは、ADOは私にすべてのエラーを送信しませんでした...これは私のスクリプトですテーブルバンク

USE [tss_dev] 
GO 

/****** Object: Table [dbo].[banks] Script Date: 26/04/2012 11:17:08 ******/ 
SET ANSI_NULLS ON 
GO 

SET QUOTED_IDENTIFIER ON 
GO 

SET ANSI_PADDING ON 
GO 

CREATE TABLE [dbo].[banks](
    [id_bank] [smallint] IDENTITY(22,1) NOT NULL, 
    [desc_bank] [char](30) NOT NULL, 
CONSTRAINT [PK_banks_id_bank] PRIMARY KEY CLUSTERED 
(
    [id_bank] ASC 
)WITH (PAD_INDEX = OFF, STATISTICS_NORECOMPUTE = OFF, IGNORE_DUP_KEY = OFF, ALLOW_ROW_LOCKS = ON, ALLOW_PAGE_LOCKS = ON) ON [PRIMARY] 
) ON [PRIMARY] 

GO 

SET ANSI_PADDING OFF 
GO 

EXEC sys.sp_addextendedproperty @name=N'MS_SSMA_SOURCE', @value=N'tss_sales_demo.banks' , @level0type=N'SCHEMA',@level0name=N'dbo', @level1type=N'TABLE',@level1name=N'banks' 
GO 

おかげさまで皆さんを助けてください.. !!!

答えて

0

は私がADODBアクティブなレコード

class MSSQL_Active_Record extends ADOdb_Active_Record { 
    // The fix for default save method which is error in MSSQL 
    function Save($pk = 'id') 
    { 
     $db = $this->DB(); 
     $db->Execute("SET IDENTITY_INSERT {$this->_table} ON"); 

     $this->$pk = $this->LastInsertID($db, $pk) + 1; 
     parent::Save(); 

     $db->Execute("SET IDENTITY_INSERT {$this->_table} OFF"); 
    } 
} 
を使用しての保存方法MSSQLを修正するために、このオーバーライドクラスを使用します