I want to insert arabic values, so i used this syntax :
$sql = "
insert into sdka_creation (creation_time, sdka_for, creator_ip)
values ('$creation_time',N\'$name\', '$creator_ip')
";
// or N"$name"
this gives me this error :
Fatal error: Uncaught TypeError: sqlsrv_rows_affected(): Argument #1 ($stmt) must be of type resource, bool given in C:\xampp\htdocs\quran\go.php:443 Stack trace: #0 C:\xampp\htdocs\quran\go.php(443): sqlsrv_rows_affected(false) #1 {main} thrown in C:\xampp\htdocs\quran\go.php on line 443
and other time :
$fnmae = N'$name';
$sql = "
insert into sdka_creation (creation_time, sdka_for, creator_ip)
values ('$creation_time','$fname', '$creator_ip')
";
this gives me synatx error :
Syntax error: unexpected token ''$name''
how could be solved ?
Note : db type is nvarchar
summary (all of these errors) :
$sql = "
insert into sdka_creation (creation_time, sdka_for, creator_ip)
values ('$creation_time',N\'$name\', '$creator_ip')
";
and :
$fnmae = N'$name';
Related
When querying a SQL Server database from PHP with this statement:
SELECT [Value] FROM sys.extended_properties WHERE name='MS_Description'
I get this error message:
"Fatal error: Uncaught exception 'PDOException' with message 'SQLSTATE[IMSSP]: Invalid type.' in C:\inetpub\wwwroot\index.php:104 Stack trace: #0 C:\inetpub\wwwroot\index.php(104): PDOStatement->fetch(2) #1 {main} thrown in C:\inetpub\wwwroot\index.php on line 104"
The php that I'm using is below, line 104 is the start of the While loop:
$sql = "SELECT [Value] FROM sys.extended_properties WHERE name='MS_Description'";
global $pdo;
$qry = $pdo->query($sql);
if (!$qry) {
exit('<pre>' . print_r($qry->errorInfo()));
}
while($row = $qry->fetch(PDO::FETCH_ASSOC)) {
foreach ($row as $key => $value) {
echo '<p>Key: ' .$key. ', Value: ' .$value. '</p>';
}
}
The code above works fine when selecting from any other table or view e.g:
SELECT * FROM sys.events
If I execute the statement via SSMS it works fine, any ideas why it doesn't work via PHP?
Casting the columns being selected as varchar(255) solved the problem i.e.
$sql = "SELECT CAST([Value] AS VARCHAR(255)) FROM sys.extended_properties WHERE name='MS_Description'";
Got to the solution based on the answers to this question and this question.
I am trying to insert to a oracle table using pdo. Its getting an error:
Fatal error: Uncaught exception 'PDOException' with message
'SQLSTATE[HY000]: General error: 1843 OCIStmtExecute: ORA-01843: not a
valid month` (ext\pdo_oci\oci_statement.c:148)' in
D:\xampp\htdocs\ipack\insertstatus.php:60 Stack trace: #0
D:\xampp\htdocs\ipack\insertstatus.php(60): PDOStatement->execute() #1
{main} thrown in D:\xampp\htdocs\ipack\insertstatus.php on line 60
This is my code:
$today = date("d-m-Y");
$stmt = $dbh->prepare("INSERT INTO PRTJOBSTATUS (INTJOBNO,SLNO,OPDATE,OPERTYPE,OPUSER,REMARKS,STATUSCODE,STATDATE)
values (:intjn,:sn,:opdt,:optype,:opusr,:rmks,:stcd,:stdt)");
$stmt->bindParam(':intjn',$intjobno);
$stmt->bindParam(':sn',$slno);
$stmt->bindParam(':opdt',$today);
$stmt->bindParam(':optype',$optype);
$stmt->bindParam(':opusr',$opuser);
$stmt->bindParam(':rmks',$remarks);
$stmt->bindParam(':stcd',$statuscode);
$stmt->bindParam(':stdt',$today);
if($stmt->execute()) {
echo '1 row has been inserted';
}
$dbh = null;
You're inserting into a column "STATDATE". I would imagine this will be of type Date. Therefore you'll have to pass a date object into the insert statement.
Change your $today variable to return a string in the following format 'DD-MON-YYYY' eg 31-DEC-2015
Then change your insert statement to the following:
"INSERT INTO PRTJOBSTATUS (INTJOBNO,SLNO,OPDATE,OPERTYPE,OPUSER,REMARKS,STATUSCODE,STATDATE)
values (:intjn,:sn,:opdt,:optype,:opusr,:rmks,:stcd,TO_DATE(:stdt,'DD-MON-YYYY'))"
I am inserting the values using PDO but i am getting error as:
Fatal error: Uncaught exception 'PDOException' with message 'SQLSTATE[42000]: Syntax error or access violation: 1064 You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near 'desc,price,nick_name,gender,size,color,birth_date,uname,uphone,ucountry,ustate,u' at line 1' in C:\wamp\www\aa\abc.php:58 Stack trace: #0 C:\wamp\www\www\aa\abc.phpphp(58): PDOStatement->execute(Array) #1 {main} thrown in C:\wamp\www\www\aa\abc.php.php on line 58
also getting Warning: implode() [function.implode]: Bad arguments for implode function
Code:
foreach ($_POST['pcheck'] as $p_check) ////storing checkbox values
{
$pcheckp[] = $p_check;
} $finalcheck = implode(',', $pcheck);
foreach ($_POST['pinc'] as $p_inc) ////storing inputfield values
{
$pinc[] = $p_inc;
} $finalpinc = implode(',', $pinc);
$sql = "INSERT INTO list (u_id,list_type,list_ff,breed,title,desc,price,nick_name,gender,size,color,birth_date,uname,uphone,ucountry,ustate,ucity,usite,pcheck,pinc,photo)
VALUES(:uid,:list_type,:list_ff,:breed,:title,:desc,:price,:nick_name,:gender,:size,:color,:date,:uname,:uphone,:ucountry,:ustate,:ucity,:usite,:pcheck,:pinc,:p_photo)";
$q = $db->prepare($sql);
$q->execute(array(':uid'=>dd,
':list_type'=>$list_type,
':breed'=>$breed,
':title'=>$title,
':desc'=>$desc,
':price'=>$price,
':list_ff'=>$list_ff,
':nick_name'=>$nick_name,
':gender'=>$gender,
':size'=>$size,
':color'=>$color,
':date'=>$date,
':uname'=>$uname,
':uphone'=>$uphone,
':ucountry'=>$ucountry,
':ustate'=>$ustate,
':ucity'=>$ucity,
':usite'=>$usite,
':pcheck'=>$finalcheck,
':pinc'=>$finalpinc,
':p_photo'=>$p_photo));
$_POST['pcheck'] and $_POST['pinc'] is used to get checkbox and input values which i am going to store in column in mysql.
I have checked many times to find the syntax error in insert query but nothing wrong is in it
Hoping to get help
Thanks!
for Warning: implode()
$finalcheck = implode(',', $pcheck);
should be
$finalcheck = implode(',', $pcheckp);
also desc is reserved for mysql you need to use it with `
$sql = "INSERT INTO list (`u_id`,`list_type`,`list_ff`,`breed`,`title`,`desc`,`price`,`nick_name`,`gender`,`size`,`color`,`birth_date`,`uname`,`uphone`,`ucountry`,`ustate`,`ucity`,`usite`,`pcheck`,`pinc`,`photo`)
VALUES(:uid,:list_type,:list_ff,:breed,:title,:desc,:price,:nick_name,:gender,:size,:color,:date,:uname,:uphone,:ucountry,:ustate,:ucity,:usite,:pcheck,:pinc,:p_photo)";
I keep getting this error message. The datatype it's talking about is TEXT and the data to insert is TEXT so I don't see what could be the problem.
robin#robin-Latitude-D620:/media/Data/Documenten/PHP/µBot$ php index.php
PHP Warning: PHP Startup: Unable to load dynamic library '/usr/lib/php5/20090626/sqlite.so' - /usr/lib/php5/20090626/sqlite.so: cannot open shared object file: No such file or directory in Unknown on line 0
PHP Fatal error: Uncaught exception 'PDOException' with message 'SQLSTATE[HY000]: General error: 20 datatype mismatch' in /media/Data/Documenten/PHP/µBot/index.php:100
Stack trace:
#0 /media/Data/Documenten/PHP/µBot/index.php(100): PDOStatement->execute()
#1 /media/Data/Documenten/PHP/µBot/index.php(73): addToLog('439', '*', 'irc.gmake.org', ':Please wait wh...')
#2 {main}
thrown in /media/Data/Documenten/PHP/µBot/index.php on line 100
Block of code where the problem should lie (line 100 is the last line of this block):
function addToLog($type, $channel, $host, $message)
{
global $database;
$temp = explode('!', $host);
$nick = $temp[0];
unset($temp);
$timestamp = time();
$nickprefix = '';
$query = $database->prepare("INSERT INTO log VALUES ('', :channel, :nick, :host, :message, :type, :time, '');");
$query->bindParam(':channel', $channel);
$query->bindParam(':nick', $nick);
$query->bindParam(':host', $host);
$query->bindParam(':message', $message);
$query->bindParam(':type', $type);
$query->bindParam(':time', $timestamp);
$query->execute();
}
Full code: http://pastebin.com/CXCQjqb0
--
SQLite version: sqlite 2.8.17-6.1ubuntu1
PHP version: php5-common 5.3.6-13ubuntu3.2
I don't know your schema but I'll guess that id is an auto-increment column and this:
INSERT INTO log (id, channel, nick, host, message, type timestamp, nickprefix)
VALUES ('', :channel, :nick, :host, :message, :type, :time, '');
is trying to put an empty string in the id. You probably want this:
INSERT INTO log (channel, nick, host, message, type timestamp, nickprefix)
VALUES (:channel, :nick, :host, :message, :type, :time, '');
And please, always specify the column list with your INSERTS and simply leave out any values that the database will supply values for (this includes both auto-incrementing columns and columns with other default values).
I do not know SQLLITE, but after reading quickly in the documentation and looking specifically for the ':' attribute, I found this:
Name Of A Host Parameter
const char *sqlite3_bind_parameter_name(sqlite3_stmt*, int);
The sqlite3_bind_parameter_name(P,N) interface returns the name of the N-th SQL parameter in the prepared statement P. SQL parameters of the form "?NNN" or ":AAA" or "#AAA" or "$AAA" have a name which is the string "?NNN" or ":AAA" or "#AAA" or "$AAA" respectively. In other words, the initial ":" or "$" or "#" or "?" is included as part of the name. Parameters of the form "?" without a following integer have no name and are referred to as "nameless" or "anonymous parameters".
The first host parameter has an index of 1, not 0.
If the value N is out of range or if the N-th parameter is nameless, then NULL is returned. The returned string is always in UTF-8 encoding even if the named parameter was originally specified as UTF-16 in sqlite3_prepare16() or sqlite3_prepare16_v2().
So, the following error (looking at the message in #1) may pertain to the ':' in the text. Try to remove it from teh text and see what happens.
0 /media/Data/Documenten/PHP/µBot/index.php(100): PDOStatement->execute()
1 /media/Data/Documenten/PHP/µBot/index.php(73): addToLog('439', '*', 'irc.gmake.org', ':Please wait wh...')
2 {main}
I am working with PHP-PDO and Oracle 11g. I am working with Oracle packages which have many functions and stored procedures. Now when I make a call to one of the functions from sql*plus or sql developer IDE, I run this command to get the result set.
select package_name.function_name(param1,param2) from dual
It works fine and returns my result set. Now when I do the same, I am getting errors from the PDO Exception handling. The code with on PHP end looks like this,
$stmt = "select package_name.function_name (?,?) from dual";
$res = $this->ConnOBJ->prepare($stmt);
$param1 = '1';
$param2 = null;
$result->bindParam(1,$param1);
$result->bindParam(2,$param2);
$result->execute();
And I get back an exception which is being logged into my log file.
Uncaught exception 'PDOException' with message 'SQLSTATE[HY000]: General error: 904 OCIStmtExecute: ORA-00904: "PACKAGE_NAME"."FUNCTION_NAME"": invalid identifier (/var/www/php-5.3.3/ext/pdo_oci/oci_statement.c:146)' in /opt/web/dir/ora_class.php:209 Stack trace: #0 /opt/web/dir/ora_class.php(209): PDOStatement->execute() #1 /opt/web/dir/ora_class.php(298): dbPDO->execPackage() #2 {main} thrown in /opt/web/dir/ora_class.php on line 209
Am I passing the query in a wrong way? Or am I binding the parameters in a wrong way?
Update
I have now got the data going through to Oracle, and have found how to pass null values. My code now is
$stmt = "select package_name.function_name(?,?) from dual";
$res = $this->ConnOBJ->prepare($stmt);
$param1 = 1;
$param2 = null;
$res->bindParam(1,$param1,PDO::PARAM_INT);
$res->bindParam(2,$param2,PDO::PARAM_NULL);
$res->execute();
var_dump($res->fetchAll());
And now when I pass data, I get back the error
PHP Fatal error: Uncaught exception 'PDOException' with message 'SQLSTATE[HY000]: General error: 932 OCIStmtFetch: ORA-00932: inconsistent datatypes: expected CHAR got DTYCWD (/var/www/php-5.3.3/ext/pdo_oci/oci_statement.c:467)' in /opt/web/dir/ora_class.php:216 Stack trace: #0 /opt/web/dir/ora_class.php(216): PDOStatement->fetchAll() #1 /opt/web/dir/ora_class.php(305): dbPDO->execPackage() #2 {main} thrown in /opt/web/dir/ora_class.php on line 216
I am making sure all the types are right, but I still am getting back the same error. I even removed the null value and passed in a string, and changed the pdo type to PDO::PARAM_STR, but it still gives me the error.
Does the function take one parameter or two? In SQL*Plus, you're passing two parameters. In PHP, you're passing only one. If the function requires two parameters and there is no overloaded method that takes only one parameter, you'd get this error.
I am not using PDO anymore, I would be using OCI drivers. Thank you for all the help.
Here is a link to an answer for a similar question [LINK] : https://stackoverflow.com/a/57558306/7897970
or best
//Your connection details
$conn = oci_connect($username, $password, '(DESCRIPTION = (ADDRESS = (PROTOCOL = TCP)(HOST = 127.0.0.1)(PORT = 1521))(CONNECT_DATA = (SERVER = DEDICATED) (SERVICE_NAME = XE)))' );
/* Your query string; you can use oci_bind_by_name to bind parameters or just pass the variable in it*/
$query = "begin :cur := functionName('".$param1."','".$param2."','".$param3."'); end;";
$stid = oci_parse($conn, $query);
$OUTPUT_CUR = oci_new_cursor($conn);
oci_bind_by_name($stid, ':cur', $OUTPUT_CUR, -1, OCI_B_CURSOR);
oci_execute($stid);
oci_execute($OUTPUT_CUR);
oci_fetch_all($OUTPUT_CUR, $res);
// To get your result
var_dump($res);