Parameter Types

The driver does not attempt to determine the correct parameter type for each parameter. The default for all parameters defaults to the ODBC style SQL_CHAR value, unless you use bind_param() with a type value set to a supported bind type.

The driver supports these ODBC style bind types:

  • SQL_CHAR

  • SQL_VARCHAR

  • SQL_VARBINARY

  • SQL_LONGVARCHAR

  • SQL_LONGVARBINARY

  • SQL_BINARY

  • SQL_DATETIME

  • SQL_DATE

  • SQL_TIME

  • SQL_TIMESTAMP

  • SQL_BIT

  • SQL_TINYINT

  • SQL_SMALLINT

  • SQL_INTEGER

  • SQL_REAL

  • SQL_FLOAT

  • SQL_DECIMAL

  • SQL_NUMERIC

  • SQL_BIGINT

  • SQL_WCHAR

  • SQL_WLONGVARCHAR

The ODBC types are mapped in the driver to equivalent Adaptive Server datatypes. See the Adaptive Server Enterprise ODBC Driver by Sybase User Guide 15.7.

Execute the stored procedure, sp_datatype_info to get a full list of supported types for the particular Adaptive Server. For example:
$sth = $dbh->prepare("exec my_proc \@p1 = ?, \@p2 = ?");
	$sth->bind_param(1, 'one', SQL_CHAR);
	$sth->bind_param(2, 2.34, SQL_FLOAT);
	$sth->execute;
	....
	$sth->execute('two', 3.456);
	etc...
Note: Once you have set a column type for a parameter, you cannot change it unless you deallocate and retry the statement handle. When binding SQL_NUMERIC or SQL_DECIMAL data, you may get fatal conversion errors if the scale or the precision exceeds the size of the target parameter definition.
For example, consider this stored procedure definition:
declare proc my_proc @p1 numeric(5,2) as...
	$sth = $dbh->prepare("exec my_proc \@p1 = ?");
	$sth->bind_param(1, 3.456, SQL_NUMERIC);

which generates this error:

DBD::SybaseASE::st execute failed: Server message number=241 severity=16 state=2 line=0 procedure=my_proc text=Scale error during implicit conversion of NUMERIC value '3.456' to a NUMERIC field.

Set the arithabort option as follows to ignore these errors:

$dbh->do("set arithabort off");

See the Adaptive Server reference documentation.