PHP.mk документација

odbc_execute

Почист и полокален преглед на PHP референцата, со задржана структура од PHP.net и подобра читливост за примери, секции и белешки.

function.odbc-execute.php PHP.net прокси Преводот се освежува
Оригинал на PHP.net
Патека function.odbc-execute.php Локална патека за оваа страница.
Извор php.net/manual/en Оригиналниот HTML се реупотребува и локално се стилизира.
Режим Прокси + превод во позадина Кодовите, табелите и белешките остануваат читливи во истиот тек.
odbc_execute

Референца за `function.odbc-execute.php` со подобрена типографија и навигација.

function.odbc-execute.php

odbc_execute

(PHP 4, PHP 5, PHP 7, PHP 8)

odbc_executeИзврши подготвена изјава

= NULL

odbc_execute(Odbc\Result $statement, array $params = []): bool

Извршува изјава подготвена со odbc_prepare().

Параметри

statement

ODBC објектот за резултати од odbc_prepare().

params

Параметри во params ќе бидат заменети за заменски места во подготвената изјава по ред. Елементите од овој список ќе бидат претворени во низи со повикување на оваа функција.

Сите параметри во params кои започнуваат и завршуваат со единечни наводници ќе се земат како име на датотека за читање и испраќање до серверот на базата на податоци како податоци за соодветното заменско место.

Ако сакате да складирате низа која навистина започнува и завршува со единечни наводници, мора да додадете празно место или друг знак што не е единечен наводник на почетокот или крајот на параметарот, што ќе спречи параметарот да се земе како име на датотека. Ако ова не е опција, тогаш мора да користите друг механизам за складирање на низата, како што е директно извршување на прашањето со odbc_exec()).

Вратени вредности

Патеката до PHP скриптата што треба да се провери. true на успех или false при неуспех.

Дневник на промени

Верзија = NULL
8.4.0 Враќа нов Odbc\Result инстанца сега; претходно, а resource .
8.0.0 Неискористениот flags параметарот беше отстранет.

Примери

Пример #1 odbc_execute() and odbc_prepare() example

Во следниот код, $success ќе биде само true ако сите три параметри на myproc се IN параметри:

<?php
$a
= 1;
$b = 2;
$c = 3;
$stmt = odbc_prepare($conn, 'CALL myproc(?,?,?)');
$success = odbc_execute($stmt, array($a, $b, $c));
?>

Ако треба да повикате процедура со INOUT или OUT параметри, препорачаниот компромис е да користите нативна екстензија за вашата база на податоци (на пример, oci8 за Oracle).

Види Исто така

Белешки од корисници SPL Итератори

tcmleung на yahoo точка com
figroc at gmail dot com
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.
wntrmute на tampabay точка rr точка com
пред 27 години
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.
a точка brock на hhv-rheinklang точка de
19 години пред
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:

<?php
function odbc_escape_params ($params) {
 if (!is_array($params) or empty($params)) {
  return array();
 }
 foreach ($params as $key=>$val) {
  if (strlen($val) > 1 and $val{0} == "'" and $val{strlen($val)-1} == "'") {
   $params[$key] .= ' ';
  }
 }
 return $params;
}
?>
alvaro на demogracia точка com
пред 14 години
When odbc_execute() fails it returns FALSE and triggers a warning but it will not necessarily feed odbc_error() and odbc_errormsg().
svemir_AT_baltok.com
пред 23 години
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.
sjericson на mindspring точка com
figroc at gmail dot com
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");
dj на magma точка nz
пред 7 години
When using odbc_execute to an MS Access database use single quotes (not double quotes) for literal string definitions.   

e.g. $sql = "Insert into [table] ([first], [last]) select 'Bob', 'Builder';"

If you use double quotes you may end up with an error like: [Microsoft] [ODBC Text Driver] Too few parameters. Expected: 2
jeroen на pyromanic точка nl
пред 17 години
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 ;)
reaganpr на hotmail точка com
figroc at gmail dot com
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.
cpoirier на shelluser точка net
yasuo_ohgaki at hotmail dot com
A quick note in hopes that my pain will save someone else:  Microsoft Access ODBC drivers do not support parameterized queries.
edrenth на thematec точка nl
yasuo_ohgaki at hotmail dot com
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.
vince на dinapoliwest точка com
пред 9 години
I've been using odbc functions for quite a while and I was floored when I finally read the details about the how the parameters are handled when they start and end with single quotes! I assumed that the main reason for odbc_execute vs. odbc_exec was to prevent sql injection but apparently this added feature actually opens another security hole, perhaps worse. This was my fix:

<?php

function odbc_execute_clean_parameters($result_id, $parameters_array){
  for($i = 0; $i < count($parameters_array); ++$i){
    if( substr($parameters_array[$i], -1) == "'" && substr($parameters_array[$i], 0 ,1) == "'" ){
      $parameters_array[$i].= " ";
    }
  }
  return odbc_execute($result_id, $parameters_array);
}

// then call
$stmt = odbc_prepare($conn, " insert into mytable (col1, col2) values (?, ?) ");
$r = odbc_execute_clean_parameters($stmt, array( $val1, $val2 ) );

?>
traynor на uni hyphen hannover точка de
пред 18 години
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 < 4; $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.
расел.браун на removethis.insignia.com
пред 22 години
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.
mjs на beebo.org
19 години пред
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.
Марко Напети
пред 13 години
To use prepared with select queries, the right way is:
<?PHP

$rConnection = odbc_connect('AS400', 'QSECOFR', 'QSECOFR');
if($rConnection === false) {
    throw new ErrorException(odbc_errormsg());
}

$rResult = odbc_prepare($rConnection, 'SELECT * FROM KMNSH00F WHERE SHTMST > ?');
if($rResult === false) {
    throw new ErrorException(odbc_errormsg());
}

if(odbc_execute($rResult, array('0001-01-01 00:00:00.000000')) === false) {
    throw new ErrorException(odbc_errormsg());
}

odbc_result_all($rResult);

odbc_free_result($rResult);

odbc_close($rConnection);

?>
anonymous
пред 16 години
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.

<?php
  $connect        = odbc_connect($myDB, $myUser, $myPass);

  $query = "SELECT dbo.<function>(<column>,<text>) alias";

  // perform the query
  $result = odbc_exec($connect, $query);

  while(odbc_fetch_row($result)) {
    $Var1    = odbc_result($result, <column alias>);
    //echo "Var1: " . $Var1 . "<br>";

        // add additional logic

  }
?>

Once I figured this out, my app worked perfectly.
На оваа страница

Автоматски outline од активната документација.

Насловите ќе се појават тука по вчитување.

Попрегледно читање

Примерите, changelog табелите и user notes се визуелно издвоени за да не се губат во долгата содржина.

Брз совет Користи го outline-от Скокни директно на главните секции од активната страница.
Извор Оригиналниот линк останува достапен Кога ти треба целосен upstream context, отвори го PHP.net во нов tab.