Be part of JetBrains PHPverse 2026 on June 9 – a free online event bringing PHP devs worldwide together.

jurietylier's avatar

oci_bind_by_name(): ORA-01036: illegal variable name/number on PDO bindparam

public function unlockUser(Request $request){ $unlock_name = $request->unlock_name;

$pdo = DB::connection()->getPdo();
$sql = "ALTER USER ? ACCOUNT UNLOCK";
$unlock = $pdo->prepare($sql);
$unlock->bindParam('username', $unlock_name, PDO::PARAM_STR);
$unlock->execute();

return response()->json([
'status'=>'success',
]);

}

how to solve this i get error in oracle saying illegal name/number when im using bindparam for security purposes

0 likes
29 replies
jurietylier's avatar

i tried the bindValue but still its the same error $unlock_name = $request->unlock_name;

$pdo = DB::connection()->getPdo();
$sql = "ALTER USER ? ACCOUNT UNLOCK";
$unlock = $pdo->prepare($sql);
$unlock->bindValue(1, $unlock_name, PDO::PARAM_STR);
$unlock->execute();

return response()->json([
'status'=>'success',
]);
jurietylier's avatar

@Sinnbeck

i tried that too its still the same

$pdo = DB::connection()->getPdo(); $sql = "ALTER USER :username ACCOUNT UNLOCK"; $unlock = $pdo->prepare($sql); $unlock->bindParam('username', $unlock_name, PDO::PARAM_STR); $unlock->execute();

return response()->json([
'status'=>'success',
]);
Sinnbeck's avatar

Or

$pdo = DB::connection()->getPdo();
$sql = "ALTER USER :foo ACCOUNT UNLOCK";
$unlock = $pdo->prepare($sql);
$unlock->bindValue('foo', $unlock_name, PDO::PARAM_STR);
$unlock->execute();

return response()->json([
'status'=>'success',
]);
Sinnbeck's avatar

Are you using a package to use oracle with laravel?

Sinnbeck's avatar

@jurietylier Just reading the source code. One thing I notice is that they always add the optional : and length to -1

https://github.com/yajra/laravel-oci8/blob/b6b1a8533963ae1f3e11390340ce38ef228983ad/src/Oci8/Oci8Connection.php#L402

$pdo = DB::connection()->getPdo();
$sql = "ALTER USER :foo ACCOUNT UNLOCK";
$unlock = $pdo->prepare($sql);
$unlock->bindParam(':foo', $unlock_name, PDO::PARAM_STR, -1);
$unlock->execute();

return response()->json([
'status'=>'success',
]);
jurietylier's avatar

@Sinnbeck im trying this too the simple way the value of the lock_name will show in sql but when passing in the oracle it will show this error

"oci_bind_by_name(): ORA-01036: illegal variable name/number (SQL: ALTER USER MC21 ACCOUNT LOCK)"

Sinnbeck's avatar

@jurietylier So if you use DB::statement() you get the same error?

Can you show the exact output of dd($unlock_name);

jurietylier's avatar

@Sinnbeck Its the same error im getting eventhough i set a static value in unlock name

	$unlock_name = "Sample";
$pdo = DB::connection()->getPdo();
$sql = "ALTER USER :foo ACCOUNT UNLOCK";
$unlock = $pdo->prepare($sql);
$unlock->bindParam(':foo', $unlock_name, PDO::PARAM_STR, -1);
$unlock->execute();
Sinnbeck's avatar

@jurietylier And

So if you use DB::statement() you get the same error?

I mean instead of all that code

Sinnbeck's avatar

@jurietylier Ok then maybe try reaching out to yajra/laravel-oci8 and ask them if there could be a problem with running statements

I dont see any reason why this shouldnt work, and it is using laravel, not PDO directly.

$unlock_name = 'foo';
DB::statement('ALTER USER ? ACCOUNT UNLOCK', [$unlock_name]);
return;
Sinnbeck's avatar

@jurietylier Hm one last idea https://github.com/yajra/laravel-oci8/issues/512

DB::executeProcedureWithCursor('ALTER USER ? ACCOUNT UNLOCK', [$unlock_name]);

I also found this old issue from 2015, but I dont know if its relevant https://github.com/yajra/laravel-oci8/issues/110#issuecomment-167699551

If it is then maybe you are forced to do it without binding (if this works be sure to check for sql injections manually!!)

DB::statement('ALTER USER ' . $unlock_name' . ' ACCOUNT UNLOCK');
jurietylier's avatar

@Sinnbeck This is the error when i use that executeProcedureWithCursos "Error Code : 6550\r\nError Message : ORA-06550: line 1, column 7:\nPLS-00103: Encountered the symbol "ALTER" when expecting one of the following:\n\n ( begin case declare exit for goto if loop mod null pragma\n raise return select update while with \n <<\n continue close current delete fetch lock insert open rollback\n savepoint set sql execute commit forall merge pipe purge\r\nPosition : 6\r\nStatement : begin ALTER USER :p0 ACCOUNT UNLOCK(:0,:cursor); end;\r\nBindings : [PURE,Resource id #521]\r\n"

Tray2's avatar

You need to follow the Oracle way

https://www.php.net/manual/en/function.oci-bind-by-name.php

The first example on that page

<?php

// Create the table with:
//   CREATE TABLE mytab (id NUMBER, text VARCHAR2(40));

$conn = oci_connect('hr', 'welcome', 'localhost/XE');
if (!$conn) {
    $m = oci_error();
    trigger_error(htmlentities($m['message']), E_USER_ERROR);
}

$stid = oci_parse($conn,"INSERT INTO mytab (id, text) VALUES(:id_bv, :text_bv)");

$id = 1;
$text = "Data to insert     ";
oci_bind_by_name($stid, ":id_bv", $id);
oci_bind_by_name($stid, ":text_bv", $text);
oci_execute($stid);

// Table now contains: 1, 'Data to insert     '

?>

Please or to participate in this conversation.