Login Retreive lost passwordRegister
Search

Forum Index / General / Sybase class nearly complete

[ This topic is solved ]

  Iyas 19 December 11 / 09:17  
Hi,

Currently I'm working on Sybase class for FH.
I've successfully being able to EDIT my table using the new class.

Unfortunately, the INSERT function got error:

The error message:
Warning: class.dbFormHandler.php at 1471 Error, query failed!
Error message: ERROR
Query: INSERT INTO iyas_test ( id, ada, ferad) VALUES ( 134, 'ret', 'reg' );

What do you think the cause of the error? (Line 1471)
I run the reported query on terminal, and success.

FYI, the new class run nothing for these functions:
getInsertId
getError
getErrorNo
escapeString

  Johan Wiegel (Admin) 19 December 11 / 09:51  
What is returned by vour Query function in the new class on a insert?

dbFormHandler expects true on a successfull insert

  Iyas 20 December 11 / 05:48  
You guessed it right! The Query Function! But sadly I don't know how to overcome this problem.

sybase_query() seems not returning TRUE when doing an INSERT query.
Now I know where to put my effort. Will report back as soon as I get the solution.

  Johan Wiegel (Admin) 20 December 11 / 07:37  
seems to retrun true on success:

http://nl.php.net/manual/en/function.sybase-query.php

  Iyas 20 December 11 / 08:03  
I test this code:


$q = sybase_query("INSERT INTO iyas_test (id,ada,ferad) VALUES (324567,'sdfsg','dfsfsdf')");
print_r($q);

the output is 1. Is it same as TRUE?

  Iyas 20 December 11 / 08:32  
Yes!

Wrong target... I found "sybase_ get_ last_ message", then I put in the getError function, and it does the job!

The error message stated:
Error message: Incorrect syntax near ';'.

I've to remove semicolon from your INSERT statement in class.dbFormhandler.php. Don't know if this will be a problem for other db.

  Iyas 20 December 11 / 08:35  
Surprisingly, the semicolon doesn't give problem when I use in terminal.

  Johan Wiegel (Admin) 20 December 11 / 11:54  
you should not need to make changes to class.dbFormhandler.php.

Try to fix it in your class

  Iyas 21 December 11 / 01:23  
The class.dbFormhandler.php generates the INSERT statement, right?
Line 1639 - 1649 creates insert query ending with semicolon, how can I change that from my class?

Do you have any suggestion?

  Iyas 21 December 11 / 02:19  
I make a class that extends dbFormhandler, then my new script called the new class that have method overriding _getQuery() method.

Is this the only solution?

  Johan Wiegel (Admin) 21 December 11 / 09:02  
Changed at 21 December 11 / 09:02
We had rather see that there is no extension needed for the dbFormhandler class.

I never used Sybase but I think you should solve it in the sybase class

  Iyas 21 December 11 / 09:26  
Changed at 21 December 11 / 09:36
Sorry for being unclear.

Sybase (or my version of Sybase) has issue with semi-colon(;) in INSERT query, which is part of dbFormHandler class (in _getQuery method).

<?php 

    
function _getQuery$table$data$sqlFields$edit$keys null )
    {
        ....
                  .......
                     ...........
        
// the form is an insert form..
        
else
        {
            
// generate the insert query
            
$query 'INSERT INTO '.$this->_db->quote$this->_table )." (\n";

            
// add the field names to the query
            
foreach( array_keys($data) as $field )
            {
                
$query .= '  '$this->_db->quote$field ) .", \n";
            }

            
// add the values to the query
            
$query  substr($query0, -3) . ") VALUES (\n  ";
            
$query .= implode(",\n  "$data)."\n);";
        }

        
// return the query
        
return $query;
    }
?>


The issue
<?php
$query 
.= implode(",\n  "$data)."\n);"//<--- the semi-colon beside the \n is the problem here.
?>

So I think the only solution is to override _getQuery method just to remove the semi-colon

  Johan Wiegel (Admin) 21 December 11 / 10:58  
It seems your Sybase is not recognizing the ; as a command seperator.

Is het possible to execute
something like: " DELIMITER ; " after making the connection to sybase?
to set ; as the command seperator

Altering or overriding the _getQuery feels as an unwanted solution.

  Iyas 26 December 11 / 01:20  
Sybase does not have that command.
I tried removing the semi-colon in query method, but no success.
<?php
    
function query$query )
    {

     
$query str_replace";"""$query );

        
$this->_lastQuery $query;

     return 
sybase_query$query$this->_conn );
    
    }
?>

  Iyas 26 December 11 / 01:38  
Problem SOLVED! The immediate above method work just fine. Previously, I've mistakenly drop 1 required field i.e, different issue.

  Johan Wiegel (Admin) 26 December 11 / 10:20  
Looks good!
Keep up the good work

  Iyas 26 December 11 / 10:57  
I would like to share my Sybase ASE class.

Here's a bit of info.

1. Make sure you uncomment the php_syabase_ct.dll extension in php.ini

2. At the top of the class, I set this:
<?php
sybase_min_server_severity
(20);
?>

Feel free to adjust the number (I'm no expert, I don't really know this thing except it removes warning)

3. For connection info, you have to refer your sql.ini usually located at C:\Sybase\ini

4. This is a sample create table
<?php
/**
 * Sample CREATE TABLE
 *
 *
 *    CREATE TABLE climasdev.dbo.iyas_test5
 *    (file_no numeric IDENTITY,
 *    nama varchar(25) NULL,
 *    umur int NULL,
 *    kerja varchar(25) NULL,
 *    ic varchar(25) NOT NULL,
 *    PRIMARY KEY (file_no),
 *    UNIQUE (nama, ic))
 */
?>

Note that IDENTITY is - as I understand - as same as auto-increment field for mysql. It has to be numeric and cannot set as not null.

I'm still learning how Sybase handle composite unique key, because as for the above create statement, Sybase only accept 'nama' as UNIQUE key, not the combination of 'nama' and 'ic'.

This Sybase class doesn't have getInsertId(), getErrorNo() and escapeString().

Improvement are welcomed....

(Admin: Please tell me how to send you my Sybase class)

  Johan Wiegel (Admin) 26 December 11 / 11:38  
you can send your files to info (at) formhandler (dot) net

  Johan Wiegel (Admin) 26 December 11 / 12:04  
What is I want to insert a text containing a ;


<?php
$query 
"insert into tbl_test (text) values ('somthing i want to tell; and some more');";
?>

Need some modification I think

You only want to remove the ; at the end of the query

  Iyas 27 December 11 / 01:31  
Changed at 27 December 11 / 01:33
You are right!

Not only I have to remove the last semi-colon. I also have to check that the last semi-colon must be in INSERT statement because if not, below example will get problem:

<?php
UPDATE 
'tbl_test' SET 'field1' 'some text with semi-colon;' WHERE id 1
?>


I get this function to replace last semi-colon
(if you have better function, please let me know)

<?php

function query$query )
{

$query =  str_lreplace(";"""$query);

$this->_lastQuery $query;

return 
sybase_query$query$this->_conn );
    
}
 
function 
str_lreplace($search$replace$subject)
{
    return 
preg_replace('~(.*)' preg_quote($search'~') . '(.*?)~''' $replace ''$subject1);
}
?>

Source: http://ideone.com/vR073


To check that the query is INSERT query...
<?php
function query$query )
{

$insert //reg_exp which i don't know how to code.

if($insert)
    
$query =  str_lreplace(";"""$query);

$this->_lastQuery $query;

return 
sybase_query$query$this->_conn );
    
}
 
?>

Do you have suggestion on the regular expression to check if the query is an INSERT statement?

  Iyas 27 December 11 / 01:46  
Changed at 27 December 11 / 01:48
Just ignore the above...

I get this:

<?php
$query 
=  trim($query,";"); 
?>

  Iyas 27 December 11 / 01:52  
I'll do a few more testing before sending you the file.

  Iyas 27 December 11 / 05:58  
I'm about to send you the file, then I saw 'test' folder in 'yadal'. I test my class, got "Strict Standards: Declaration of SybaseASE::getFieldTypes() should be compatible with that of Yadal::getFieldTypes() in C:\xampp\htdocs\FH\yadal\class.SybaseASE.php on line 547"

Strangely, mysql layer (comes with FH bundle) also got the error.

  Iyas 12 January 12 / 23:40  
Hi.

Do you get the files I sent you?

  Johan Wiegel (Admin) 24 January 12 / 09:41  
No we didnt receive anything yet.

  Iyas 01 February 12 / 06:50  
Maybe the mail went to spam folder.

Anyway, here's the class: https://github.com/iyasilias/FormHandler---Sybase-connector

  Johan Wiegel (Admin) 01 February 12 / 07:47  
No mail in the spamfolder.

any way I downloaded the files and placed them in the download

  Top


powered by PHP-GLOBE   © 2004 - 2012 FormHandler. All rights reserved.   -   Open source license