error when update table with odbc in php - php

I have database with DBF format, and use the ODBC to access the database.
When i do update on the table, it returns error:
Warning: odbc_execute() [function.odbc-execute]: SQL error: [Microsoft][ODBC dBase Driver] Index not found., SQL state S0012 in SQLExecute in C:\xampp\htdocs\payroll\index.php on line 16
According to the error msg, it seems like the index not found. what index is that? how to fix?
Below is the PHP script that i use to do the query.
$odbc = odbc_connect ('payroll', '', '') or die('Error connecting to server. Server says: '.odbc_errormsg());
$upd_q = "UPDATE paytran SET empno = 22 WHERE empno = 888";
$update = odbc_prepare($odbc, $upd_q);
$result = odbc_execute($update);
odbc_close($odbc);
Same method was used to insert new record. Insert query works successfully, but not for DELETE and UPDATE query.

According to the last post in this thread,
If you have a .dbf file nowadays, more often than not, it is from a
FoxPro application. And, since you have a .cdx file, that tells you
it is a FoxPro compound index file and dBASE can't use it and
certainly can't take advantage of it to get any speed advantage that
you would like in your queries.
Do you have a .cdx file? If so, you may want to check which version you have and then find the FoxPro driver or OLE DB provider, and use that instead of ODBC. There's information on how to do it here and here; the driver and DB provider are here.

Related

mssql_connect will not connect different DB on same SQL Server

$conn_161 = "192.168.0.161"; //local serwer adress
$user_161 = "ME";
$pass_161 = "what_is_the_password?";
$connect_161 = mssql_connect($conn_161,$user_161,$pass_161);
mssql_select_db ( 'DUKENUKEN3D' , $connect_161 );
//as requested - 1st DB connection and 1st query
$q_duke = "select * from DUKE /*DB1*/";
$r_duke = mssql_query($q_wartownik,$connect_161); //result
$connect_different_db = mssql_connect($conn_161,$user_161,$pass_161);
mssql_select_db ( 'BIGMAN' , $connect_different_db );
//second db and query
$q_bigman = "select * from BIGPEOPLE /*DB2*/";
$r_bigman = mssql_query($q_bigman,$connect_different_db ); //result
Error:
Warning: mssql_query() [function.mssql-query]: message: Invalid object name 'DUKE'.
Yes I know mssql_select_db is old, but I need to use it in this project. As you see I try to connect to same server but select 2 different DB at the same time, and run queries in the same php page (to connect data from 2 different DB). It seems it is not valiable? I even tried to run mssql_select_db just before doing the query to second DB, and then changing it back to first DB.
I understand this is limitation of the library (I will run all queries from LAST selected DB).
Is there a workaroud? Because all I got is to create page inside invisible iframe and there run php page with different db connection - far from good solution.
I would expect that this will work the same as it would if you were running this in a SQL environment directly (e.g. you can try it in SSMS or from the command line).
You can specify the database name when you reference the table in the query: e.g.
select * from db1.dbo.DUKE
This is standard SQL Server behaviour whenever you want to refer to an object which is outside the context of the current database.

Connecting to Peachtree database using php?

Iam developing an application in php which can fetch transaction,invoices.etc from peachtree database. So for database access I selected ODBC method by connecting using Pervasive SQL.
I used connection string like this:-
$connection = odbc_connect("DRIVER={Pervasive ODBC Engine Interface};Dbq=C:\Sagepro\Peachtree\Company\Sample\PAW\BCS","Peachtree","password");
But it is giving error
( ! ) Warning: odbc_connect() [function.odbc-connect]: SQL error: [Pervasive][ODBC Client Interface][LNA][Pervasive][ODBC Engine Interface][Data Record Manager]Cannot locate the named database you specified(Btrieve Error 2301), SQL state S1000 in SQLConnect in C:\wamp\www\peachtreeapi\index.php on line 2
How to rectify this??
Use this connection string.. it will work
$connect=odbc_connect("Driver={Pervasive ODBC Engine Interface};ServerName=localhost;ServerDSN=DSNname;","Username","Password",SQL_CUR_USE_ODBC);
I think this connection string will work:-
$dbhandle = odbc_connect("DSN=YOURDSN;DRIVER={Pervasive ODBC Engine Interface};DATAPATH=c:\peachw\YOURCOMPANY;DDFPATH=c:\peachw\YOURCOMPANY","username","password");
username & password is the details you provided in peachtree -> maintain->users->setupsecurity->data access/crystalreport ->All option in your peachtree app.
You'll need to create a Pervasive Database Name pointing to your data location. You can't specify a path in the connection string. Pervasive removed that functionality. Once you create the Database Name through the Pervasive Control Center, you would specify that name in your connection string:
$connection = odbc_connect("DRIVER={Pervasive ODBC Engine Interface};Dbq=XXXXXXXX","Peachtree","password");
where "XXXXXXXX" is the name of the database you created in the PErvasive Control Center.

Using PHP to connect to MS Access DB using ODBC keeps on locking

I know this is not the best setup, but I'm stuck with it and cannot change it.
PHP connects to a local MS Access DB (.mdb) to log certain activities being done by the script. This works fine when only one instance of the script is running. However, if run two instances, I occasionally get the following error:
odbc_exec(): SQL error: [Microsoft][ODBC Microsoft Access Driver] Could not update; currently locked., SQL state S1000 in SQLExecDirect
This only happens intermittently so I'm assuming it's only when the two scripts both happen to be trying to write to the same table at the same time. I never had this issue with other DBs such as MySQL. How can I tell PHP/ODBC/Access to either not lock or try again if it is locked?
I also usually have the Access DB open on my screen for troubleshooting purposes.
odbc_exec() returns FALSE if the query fails, so you could just check the result of the query and keep trying until it succeeds:
$sql = "UPDATE [Clients] SET [Position]='somewhere' WHERE [ID]=1";
while (TRUE) {
$result = odbc_exec($conn, $sql);
if ($result) {
break;
}
else {
$lastError = odbc_error();
if ($lastError != "S1000") {
echo "ODBC error $lastError";
break;
}
}
sleep(1);
}

PHP LOAD DATA INFILE Error Reading File

Solved
So, it was a type of permission error. Earlier in this script, I used flock() on the file to make sure the file wasn't being written to by another script. Removing flock() allows the query to run. Now I just need to determine a way to not load a file if it is still being written to...
I'm having trouble getting LOAD DATA INFILE to work in my php script. Here's the relevant portions of the script:
... //set $host, $user, etc.
$dsn = "mysql:host=$host;dbname=$database";
$pdo = new PDO($dsn, $user, $password, array(PDO::MYSQL_ATTR_LOCAL_INFILE => 1));
$pdo->setAttribute(PDO::ATTR_ERRMODE, PDO::ERRMODE_EXCEPTION);
... //set $sqlFile and $table
$sql = "LOAD DATA INFILE '$sqlFile' REPLACE INTO TABLE `$table`";
echo $sql . "\n";
$rows = $pdo->exec($sql);
Running the script then produces:
LOAD DATA INFILE 'D:/pathToTemp/emdr/emdrorders/emdrorders_160314-1947UTC.txt'
REPLACE INTO TABLE `emdrorders`
[PDOException]
SQLSTATE[HY000]: General error: 2 Error reading file 'D:\pathToTemp\emdr\emdrorders\emdrorders_160314-1947UTC.txt'
(Errcode: 13 - Permission denied)
However, if I run the same query through the mysql cli it works.
mysql> LOAD DATA INFILE 'D:/pathToTemp/emdr/emdrorders/emdrorders_160314-1947UTC.txt'
REPLACE INTO TABLE `emdrorders`;
Query OK, 5487 rows affected (0.10 sec)
Records: 5355 Deleted: 132 Skipped: 0 Warnings: 0
I've also tried using LOCAL, but instead of throwing an exception $pdo->exec() returns 0 and the data is not loaded into the database.
My Mysql is 5.6.12 and PHP is 5.4.16 on a Windows machine and planning to put it on linux server. (I'm also doing this within the Laravel framework but I don't think that would cause this problem.)
Since the query works in the mysql cli but not through php, I can only assume the problem is in the php settings or the pdo. What do I need to change?
What is it that you plan on doing with $rows?
You pass queries through PDO::QUERY or PDO::PREPARE.
I assume from the use of PDOStatement::execute that you wish to use PDO::PREPARE.
$query = $pdo->prepare($sql); $query->execute();
To obtain responses from the query:
$query->fetch() or $query->fetchAll()
See link for documentation on preparing a query in PDO:
http://www.php.net/manual/en/pdo.prepare.php

The request for <procedure> failed because <procedure> is a procedure object. SQL error 37000

I'm trying to use the SDK for the 123insight MRP system. In the SDK, there is one particular routine called SDK.BOMInsertSDK. Whenever I attempt to execute a SQL query from PHP through the ODBC driver, this fails with the error.
Warning: odbc_exec(): SQL error: [Microsoft][ODBC SQL Server Driver][SQL Server]
The request for procedure 'BOMInsertSDK' failed because 'BOMInsertSDK' is a
procedure object., SQL state 37000
What confuses me about this error: I can type the query in to Microsoft SQL Server Management Express and the query will execute successfully. Also, some other routines like ProductionSDK. SubOperationTestResultBooking work, but others like SDK.PartInsertSDK do not work. It seems almost random as to what I can execute and what I cannot. What could cause this?
Here's a screenshot of the relevant SDK documentation:
Here is my query, in case it matters:
EXECUTE [SDK].[BOMInsertSDK] #strParentPartNumber = "20-01-702",
#nSequenceNumber = 1234,
#strChildPartNumber = "01-07-001-R",
#decScrapPercentage = 0,
#decQuantity = 1, #blnIsPrime = 1,
#strMethodType = "Manufactured",
#strVersionNumber = "0001",
#blnInheritSerial = 0,
#strComments = "no comment"
Any advice appreciated.

Categories