472,984 Members | 2,424 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 472,984 software developers and data experts.

SQL Insert Error

Ok I'm having a problem with a SQL insert going to a Access database...here
is the connection code:

// PHP db connection
$db = 'C:\\Phpweb\\test.mdb';
$conn = new COM('ADODB.Connection');
$conn->Open("Provider=Microsoft.Jet.OLEDB.4.0; Data Source=$db");
$query = $conn->Execute($sql);

Here is the print out of the SQL:

INSERT INTO
[Cards]([active],[division],[province],[filetitle],[air],[water],[sewage],[p
ttw],[partVIII],[part46]) VALUES ('1','ob','Ontario','0 0 0
0','1','1','1','1','1','1')

Here is the errors:

Warning: (null)(): Invoke() failed: Exception occurred. Source: Microsoft
JET Database Engine Description: Syntax error in INSERT INTO statement. in
c:\phpweb\admin.card.view.php on line 193

Warning: (null)(): Invoke() failed: Exception occurred. Source:
ADODB.Connection Description: Arguments are of the wrong type, are out of
acceptable range, or are in conflict with one another. in
c:\phpweb\admin.card.view.php on line 196

Warning: main(): PropGet() failed: Exception occurred. Source:
ADODB.Connection Description: Arguments are of the wrong type, are out of
acceptable range, or are in conflict with one another. in
c:\phpweb\admin.card.view.php on line 197

Any help would be greatly appricated!!

Thanks
Jul 17 '05 #1
1 3650
Matthew Paterson wrote:
Ok I'm having a problem with a SQL insert going to a Access database...here
is the connection code:

// PHP db connection
$db = 'C:\\Phpweb\\test.mdb';
$conn = new COM('ADODB.Connection');


This is going to be expensive and less than reliable.

Do yourself a favour and use PEAR:DB
you can change to a real RDBMS later and your code will be none the
wiser. Here is a class I wrote as part of an MSAccess db app.

You need only look at the constructor if you don't want to use the rest.

Warning: the ODBC driver for PEAR:DB has a bug. It is designed to work
with unix style odbc driver. Go to c:/php/PEAR/DB/odbc.php and change

$conn = @$connect_function($dbhost, $user, $pw);
to
$conn = @$connect_function($dsninfo['database'], $user, $pw);

on line 134

I spoke to the maintainer of odbc.php and the fault as acknowledged but
left alone.

if you have no pear directory, then go the a dos command window, change
to your php directory, and type "go-pear" (make sure you are connected
to the net).
<?php

include_once "db.php";
include_once "class_Exception.php";

class sopsDb {

var $strUser ="";
var $strPass ="";
var $strDBname = "sops";
var $strHost = "localhost";
var $strDbType = "odbc";
var $dsn;
var $db;

function sopsDb() {
$this->dsn =
$this->strDbType."://"
// .$this->strUser.":"
// .$this->strPass."@"
.$this->strHost."/"
.$this->strDBname
;
if (DB::isError($this->db = DB::connect($this->dsn)))
new
Exception($this->db->getMessage().":\n".$this->db->getUserinfo(),true);
}

function &query($sql,$complain=true) {
$res =& $this->db->query($sql);
if($complain) $this->DBerrorCheck($res,$sql);
return $res;
}

function DBerrorCheck($obj,$sql) {
if (DB::isError($obj)) {
$err = $obj->getMessage().":\n".$obj->getUserinfo();

if(stristr($obj->getUserinfo(),"duplicate values"))
$err = "The name you specified already exists.";

new Exception($err,true);
}
}

function strMSEscapeSingleQuotes(&$arrPayload,$arrFields) {
foreach($arrFields AS $field) {
$arrPayload[$field] =
str_replace("'","''",$arrPayload[$field]);
}
}

function strOdbcDateTimeFormat($intTs=0) {
if(!$intTs) $intTs=time();
// { ts '1998-05-02 01:23:56.123' }
//
http://msdn.microsoft.com/library/en...on_03_04l0.asp
$strTs = "{ts'";
$strTs .= date("Y-m-d H:i:s",$intTs);
$strTs .= "'}";
return $strTs;
}

function MsSqlPrep(&$sql) {
$sql = str_replace(" '',"," NULL,",stripslashes($sql));
}

function escapeUri($uri) {
if(strpos($uri,"\\\\") === 0)
$uri = "file://".str_replace("\\","/",$uri);
return $uri;
}

function query2d($sql) {
$arr2d = array();
$objResTaskSystems = $this->query($sql);
while($arr2d[] = $objResTaskSystems->fetchRow(DB_FETCHMODE_ASSOC));
if(is_array($arr2d)) array_pop($arr2d);
return $arr2d;
}
}

?>

Jul 17 '05 #2

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

15
by: Jack | last post by:
I have a text file of data in a file (add2db.txt) where the entries are already entered on separate lines in the following form: INSERT INTO `reviews` VALUES("", "Tony's", "Lunch", "Great...
7
by: iqbal | last post by:
Hi all, We have an application through which we are bulk inserting rows into a view. The definition of the view is such that it selects columns from a table on a remote server. I have added the...
16
by: Philip Boonzaaier | last post by:
I want to be able to generate SQL statements that will go through a list of data, effectively row by row, enquire on the database if this exists in the selected table- If it exists, then the colums...
6
by: harborboy76 | last post by:
Hi, I am trying to insert a large number of rows into a table inside a SPL. But every time, I run the SPL, the table is locked because of the INSERT. When I tried to issue a COMMIT, right after...
8
by: 73blazer | last post by:
Hello, I'm looking for a way to make some of my insert templates more readable by placing comments in between the values. I cannot seem to find a way to do this with DB2, is there a way? I'm...
3
by: MP | last post by:
Hi Posted this several hours ago to another ng but it never showed up thought i'd try here. using vb6, ado, .mdb, jet4.0, no access given table tblJob with field JobNumber text(10) 'The...
3
by: mahajanvit | last post by:
Hi one and all I got this problem during my project. So in order to solve this I made a very small application. I am trying to insert using SP and sqldatasource control. I know that while using...
9
by: anachronic_individual | last post by:
Hi all, Is there a standard library function to insert an array of characters at a particular point in a text stream without overwriting the existing content, such that the following data in...
2
by: technocraze | last post by:
Hi guys, I have encountered this error when updating the values to the MS Acess table. Error : Update on linked table failed. ODBC sql server error Timeout expired. MS Acess is my front end and...
6
by: rn5a | last post by:
During registration, users are supposed to enter the following details: First Name, Last Name, EMail, UserName, Password, Confirm Password, Address, City, State, Country, Zip & Phone Number. I am...
0
by: lllomh | last post by:
Define the method first this.state = { buttonBackgroundColor: 'green', isBlinking: false, // A new status is added to identify whether the button is blinking or not } autoStart=()=>{
2
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 4 Oct 2023 starting at 18:00 UK time (6PM UTC+1) and finishing at about 19:15 (7.15PM) The start time is equivalent to 19:00 (7PM) in Central...
0
by: Aliciasmith | last post by:
In an age dominated by smartphones, having a mobile app for your business is no longer an option; it's a necessity. Whether you're a startup or an established enterprise, finding the right mobile app...
0
tracyyun
by: tracyyun | last post by:
Hello everyone, I have a question and would like some advice on network connectivity. I have one computer connected to my router via WiFi, but I have two other computers that I want to be able to...
4
NeoPa
by: NeoPa | last post by:
Hello everyone. I find myself stuck trying to find the VBA way to get Access to create a PDF of the currently-selected (and open) object (Form or Report). I know it can be done by selecting :...
1
by: Teri B | last post by:
Hi, I have created a sub-form Roles. In my course form the user selects the roles assigned to the course. 0ne-to-many. One course many roles. Then I created a report based on the Course form and...
0
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 1 Nov 2023 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM) Please note that the UK and Europe revert to winter time on...
0
NeoPa
by: NeoPa | last post by:
Introduction For this article I'll be focusing on the Report (clsReport) class. This simply handles making the calling Form invisible until all of the Reports opened by it have been closed, when it...
0
isladogs
by: isladogs | last post by:
The next online meeting of the Access Europe User Group will be on Wednesday 6 Dec 2023 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, Mike...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.