Hi,
I am having an awful lot of trouble of getting the PDO layer to work
properly.
example code:
-----------------
$tmpArray = array (
':table' ='session',
':id' ='4364564574574576',
':user_id' ='0',
':state' ='0',
':start' ='2006-08-10 00:00:00',
':last_update' ='2006-08-10 00:00:00',
':last_id_update' ='2006-08-10 00:00:00',
':ip' ='123456789',
':agent' ='Opera',
':referer' ='whatever.php',
':data' ='whatever data');
$sql = 'INSERT INTO :table (id, user_id, state, start, last_update,
last_id_update, ip, agent, referer, data) VALUES (
:id,
:user_id,
:state,
:start,
:last_update,
:last_id_update,
:ip,
:agent,
:referer,
:data
)';
$dbh->setAttribute(PDO::ATTR_ERRMODE, PDO::ERRMODE_EXCEPTION);
$sth = $dbh->prepare($sql);
try {
$sth->execute($tmpArray);
} catch (PDOException $e) {
die('Error!: ' . $e->getMessage());
}
returns:
Error!: 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 ''session' (id, user_id,
state, start, last_update, last_id_update, ip, agent, re' at line 1
What gives?
If I hardcode the table in the SQL statement it seems to work fine. But this
should work too shouldn't it?
Cheers 2 1973
amygdala wrote:
Hi,
I am having an awful lot of trouble of getting the PDO layer to work
properly.
example code:
-----------------
$tmpArray = array (
':table' ='session',
':id' ='4364564574574576',
':user_id' ='0',
':state' ='0',
':start' ='2006-08-10 00:00:00',
':last_update' ='2006-08-10 00:00:00',
':last_id_update' ='2006-08-10 00:00:00',
':ip' ='123456789',
':agent' ='Opera',
':referer' ='whatever.php',
':data' ='whatever data');
$sql = 'INSERT INTO :table (id, user_id, state, start, last_update,
last_id_update, ip, agent, referer, data) VALUES (
:id,
:user_id,
:state,
:start,
:last_update,
:last_id_update,
:ip,
:agent,
:referer,
:data
)';
$dbh->setAttribute(PDO::ATTR_ERRMODE, PDO::ERRMODE_EXCEPTION);
$sth = $dbh->prepare($sql);
try {
$sth->execute($tmpArray);
} catch (PDOException $e) {
die('Error!: ' . $e->getMessage());
}
returns:
Error!: 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 ''session' (id, user_id,
state, start, last_update, last_id_update, ip, agent, re' at line 1
What gives?
If I hardcode the table in the SQL statement it seems to work fine. But this
should work too shouldn't it?
Cheers
It's a bit frustrating, but you can't use the place holders in all
spots. The exact places you can use it, I don't know. It probably
depends on if the prepare() is emulated or not, and what the underlying
server supports.
It's a bit frustrating, but you can't use the place holders in all
spots. The exact places you can use it, I don't know. It probably
depends on if the prepare() is emulated or not, and what the underlying
server supports.
Aha, i was afraid that that was the case :(
Thanks! This thread has been closed and replies have been disabled. Please start a new discussion. Similar topics
by: Randy Rodent |
last post by:
I have a problem with some SQL code that can be run at the mySQL
command prompt, and in PHP, I can prepare it with no problem, but I
get a syntax error when I try and exexute it.
$sql = <<< EOF...
|
by: claus.hirth |
last post by:
I wrote a stored procedure that uses a prepared INSERT INTO statement
in order to play with the PREPARE and EXECUTE keywords.
In transcript 1 below the call to that stored procedure does not...
|
by: Rajat Katyal |
last post by:
Hi:
I prepare the statement for execution as follows:
PREPARE query(text) as SELECT count(*) FROM transform_customer_billing where inv_no = $1;
The problem is Iam not able to execute this...
|
by: rAinDeEr |
last post by:
Hi,
I have started using DB2 UDB ESE v8.2 in Linux recently. I have
seen a lot of articles on packages, prepare statement, bind and execute
statement.
I havent got a clear idea.
I have...
|
by: gmccammon |
last post by:
I'm having problems with my Prepare and Execute statements.
I get a syntax error onmy prepare and of course the execute won't run on an undefined value.
I don't know what I am overlooking.
...
|
by: gp |
last post by:
******************************************************************************************************************************
Catchable fatal error: Object of class stdClass could not be...
|
by: Rowan |
last post by:
When I run a small test script I get the following error.
___________________________
PHP Fatal error: Call to a member function prepare() on a non-object
in /usr/local/lib/php5/pg_connect.php on...
|
by: Gilles Ganault |
last post by:
Hello
I use the prepare/execute combo to generate SQL statements. Is it
possible to actually see what PDO creates with prepare()?
=======
$sql = "INSERT INTO mytable (id, label) VALUES...
|
by: pankaj17 |
last post by:
hello everyone,
MYSQL query ............
how to set prepare stmt result in variable
i have written prepare stmt in store procedure and i want to set result of prepare stmt in variable
...
|
by: Charles Arthur |
last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
|
by: ryjfgjl |
last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
|
by: ryjfgjl |
last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
|
by: emmanuelkatto |
last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud.
Please let me know.
Thanks!
Emmanuel
|
by: nemocccc |
last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
|
by: Hystou |
last post by:
There are some requirements for setting up RAID:
1. The motherboard and BIOS support RAID configuration.
2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
|
by: marktang |
last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
|
by: Hystou |
last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
|
by: Oralloy |
last post by:
Hello folks,
I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>".
The problem is that using the GNU compilers,...
| |