[PHP-DB] MSSQL INSERT query problem

2004-08-05 Thread Chris
Here is the code I use:

$dsn = mssql://username:[EMAIL PROTECTED]/database;

$options = array(
'debug'   = 2,
'portability' = DB_PORTABILITY_ALL,
);

$db = DB::connect($dsn, $options);
if (DB::isError($db)) {
 $db-getDebugInfo();
 die($db-getMessage());
}

$sql = $db-prepare(INSERT INTO ExitSurveyAnswers (session_id,
Question_id, answer) VALUES ?,?,?);

// Always check that result is not an error
if (DB::isError($sql)) {
 $sql-getDebugInfo();
 die($sql-getMessage());
}

$alldata = array($id,$question,$answer);

$res = $db-execute($sql, $alldata);
 print_r ($res);
if (DB::isError($res)) {
 $res-getDebugInfo();
 die($res-getMessage());
}

$db-disconnect();

When I execute it I keep recieving and error message stating:
DB Error: syntax error

I use PEAR DB and PEAR HTTP SESSION.

Any ideas will be helpful.

Thanks,
Chris

-- 
PHP Database Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php



Re: [PHP-DB] MSSQL INSERT query problem

2004-08-05 Thread John Holmes
Chris wrote:
Here is the code I use:
[snip]
$sql = $db-prepare(INSERT INTO ExitSurveyAnswers (session_id,
Question_id, answer) VALUES ?,?,?);
[snip]
When I execute it I keep recieving and error message stating:
DB Error: syntax error
Not a MSSQL expert, but shouldn't the ?,?,? in your query have 
parenthesis around it??

 $sql = $db-prepare(INSERT INTO ExitSurveyAnswers (session_id,
 Question_id, answer) VALUES (?,?,?));
--
John Holmes
php|architect - The magazine for PHP professionals - http://www.phparch.com
--
PHP Database Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php


Re: [PHP-DB] mssql insert

2004-03-28 Thread Miles Thompson
$query = INSERT INTO myTable VALUES ('.$myVar.');';
Check the commas?
Miles
At 05:50 PM 3/28/2004 +1200, Martin Ryan wrote:
Got a dumb-ass question for you all.  I have got insert queries working with
mssql_query($query); except if any of the variables have two or more words.
For example:
$myVar = Two or more words;
$query = INSERT INTO myTable VALUES ('.$myVar.');';
mssql_query($query,$db);
The query will only insert Two.

I know the query is correct, because I've echoed it, cut it, and pasted it
directly into Query Analyzer and it comes up roses.
Cheers muchly,
Marty
--
PHP Database Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php
--
PHP Database Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php


[PHP-DB] mssql: insert a record and return the auto increment ID

2002-09-02 Thread Heiko Mundle

I insert a new record with PHP into my MS SQL Server database.
The key is defined with
auto_idINT IDENTITY(1000,1) NOT NULL,

how do I get the new id to use it in PHP?

To insert the record I use this code:
$sSql = INSERT INTO myTable (time_in ) VALUES ( getdate() );
$pResult = mssql_query($sSql, $g_pDBServer);


Thanks a lot for your help

Heiko



-- 
PHP Database Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php