php autoexecute,odbc_execute

用户评论:

[#1]

Marco Napetti [2012-10-25 10:18:43]

To use prepared with select queries, the right way is:

$rConnection=odbc_connect('AS400','QSECOFR','QSECOFR');

if($rConnection===false) {

throw newErrorException(odbc_errormsg());

}$rResult=odbc_prepare($rConnection,'SELECT * FROM KMNSH00F WHERE SHTMST > ?');

if($rResult===false) {

throw newErrorException(odbc_errormsg());

}

if(odbc_execute($rResult, array('0001-01-01 00:00:00.000000')) ===false) {

throw newErrorException(odbc_errormsg());

}odbc_result_all($rResult);odbc_free_result($rResult);odbc_close($rConnection);?>

[#2]

alvaro at demogracia dot com [2011-12-20 05:16:51]

When odbc_execute() fails it returns FALSE and triggers a warning but it will not necessarily feed odbc_error() and odbc_errormsg().

[#3]

anonymous [2009-04-29 11:32:43]

if you can't use php_mssql module in your environment (suse linux, apache2, php5, FreeTDS, unixODBC) an alternative is to use sql server functions instead of procedures. here is my sample code.

$connect=odbc_connect($myDB,$myUser,$myPass);$query="SELECT dbo.(,) alias";// perform the query$result=odbc_exec($connect,$query);

while(odbc_fetch_row($result)) {$Var1=odbc_result($result, );//echo "Var1: " . $Var1 . "
";

// add additional logic}?>

Once I figured this out, my app worked perfectly.

[#4]

jeroen at pyromanic dot nl [2008-06-05 13:05:54]

If you want to use stored procedures with MSSQL over ODBC, please read

http://www.sitepoint.com/article/php-microsoft-sql-server/2

It can you save lots of time ;)

[#5]

traynor at uni hyphen hannover dot de [2007-11-08 06:09:12]

Obdc_prepare and obdc_execute can only be used as an alternative to odbc_exec in limited circumstances:

$con = obdc_connect ($dsn, $user, $pass);

$sql = "select * from TABLE";

$result = obdc_exec ($con, $sql); //this line can be replaced as blow

//then to see results:

odbc_result_all ($result);

odbc_free_result ($result);

odbc_close ($con);

gives the same result with the middle line as:

$result = odbc_prepare ($con, $sql);

odbc_execute ($result);

as long as $sql contains a well formed and complete query.

There is no point in trying to convert this into a parameter query with question marks as placeholders, since code like this will result only in error messages:

$sql = "select * from TABLE where needle = ?";

$result = odbc_prepare ($con, $sql);

for ($i = 0; $i 

{

odbc_execute ($result, array ($i));

// and whatever you want to do with the result

// but all you get is "parameter expected" or "count does not match"

}

The lack of documentation for such functions should have been an alarm signal.

[#6]

a dot brock at hhv-rheinklang dot de [2006-08-24 04:38:09]

I have a solution for the problem with the strings beeing interpreted as filename because of the single quotes:

Just add a blank to the end of the string:

if (!is_array($params) or empty($params)) {

return array();

}

foreach ($paramsas$key=>$val) {

if (strlen($val) >1and$val{0} =="'"and$val{strlen($val)-1} =="'") {$params[$key] .=' ';

}

}

return$params;

}?>

[#7]

mjs at beebo dot org [2006-03-27 01:57:23]

Don't miss the part where it says that if your string starts and ends with a single quote, the string is interpreted as a filename!

This means that you can't do:

$sth = odbc_prepare($dbh, "INSERT INTO people(name) VALUES(?)");

$res = odbc_execute($sth, array($name));

without checking the value of $name--if $name is, say, '\\'c:\\passwords.txt\\'' the contents of c:\\passwords.txt get inserted into your database as a "name".

Also, despite what the documentation suggests, there (incredibly) doesn't appear to be any way to escape your single quotes (via experimentation, and from reading the source): if your string starts and ends with a single quote you cannot use odbc_execute to insert it into the database.

[#8]

russell dot brown at removethis dot insignia dot com [2004-02-09 12:55:26]

In reply to tcmleung at yahoo dot com (09-Nov-2001), I would add a caveat that I've found, which is that the odbc.defaultlrl/odbc_longreadlen() values may only apply to odbc->php conversion and not php->odbc (though this may be database-specific). Hence, if you want to post binary data the 4096 byte limit still stands. So you stand a better chance of being able to post binary data using the quoted filename upload procedure described above, rather than using the prepare... execute method with data held in a php variable.

[#9]

svemir_AT_baltok.com [2002-09-06 10:45:21]

In reply to cpoirier's note from 04-Mar-2001 03:30:

Currently, Access 2000 DOES support parametrized queries via ODBC. It still seems to have a problem with Memo and OLE fields, but "normal" types work just fine.

[#10]

tcmleung at yahoo dot com [2001-11-09 01:22:18]

odbc has a maximum buffer size, that means it only stores and retrieves a limited size of data to/from database each time. The maximum buffer size is 4096 and set in php.ini (odbc.defaultlrl). You can set it to higher value for larger data access.

[#11]

sjericson at mindspring dot com [2001-08-25 22:43:43]

I don't think odbc_prepare and odbc_execute support output parameters for stored procedures on MSSQL.  An example of output parameters for MSSQL is at  http://support.microsoft.com/support/kb/articles/q174/2/23.asp

Also, my MSSQL driver seems happy only when I use the following incantation:

...code removed...

$stmt=odbc_prepare($conn_id, "exec my_proc_name ?,?,?");

$parms=array("fred","password",5);

if (!odbc_execute($stmt, &$parms)) die("odbc_execute failed");

[#12]

reaganpr at hotmail dot com [2001-07-23 16:50:58]

When running the CGI version of 4.0.6 under windows, I came across this error when trying to call a stored procedure in SQL Server using odbc_execute w/ the parameter array set:

FATAL:  emalloc():  Unable to allocate 268675669 bytes

Scary error, huh? In my case it just meant that SQL Server couldn't find the stored procedure.  Totally my fault, but a rather nondescript error message.

p.

[#13]

cpoirier at shelluser dot net [2001-03-04 02:30:15]

A quick note in hopes that my pain will save someone else:  Microsoft Access ODBC drivers do not support parameterized queries.

[#14]

edrenth at thematec dot nl [2000-10-17 06:17:55]

When used with parameters and the statement fails, you cannot use different arguments anymore, the same arguments as with the failed statement will be used.

[#15]

tony dot wood at revolutionltd dot com [1999-05-27 16:08:40]

For a simple database insert to a database that has no password and $from and $to are predefined variables.

}odbc_close($conn);?>

[#16]

wntrmute at tampabay dot rr dot com [1998-08-15 21:22:58]

Solid Issue:

Solid defines CHAR, VARCHAR, LONG VARCHAR, BINARY, VARBINARY, and LONG VARBINARY to be a maximum of 2G in length.  However, when creating your tables for use with PHP one should choose LONG VARCHAR or LONG VARBINARY for these kinds of fields if you are planning on storing really large or lengthy data.  IE: Data exceeding 64k in length such as GIF/JPG, or really huge text areas.

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值