Take the 2-minute tour ×

A PHP application on the server is saving a certain document with a sequential number into a MySQL database. How to obtaion that sequential number to a command line prompt that initiates the local doocument scanner?


c:\myscan ask_for_current_seq_nmbr.pdf

myscan is something written in c that takes care of the PC stuff. Only the name of file is unknown.

Some code (from the query PHP file)

$query = "SELECT last_seq FROM seq_table WHERE cat = 1";

$result = mysql_query($query, $link) or die('ERROR: '. mysql_error().'<br />ON LINE: '.__LINE__);

while($row = mysql_fetch_assoc($result)) {
    echo $row['last_seq'];

!!! NOTE !!! I am fetching a page from a remote server. ex. www.site.com/query.php?q=SELECT * FROM... And that selection results in the last used sequential number which I would like to use in my command prompt.

!! UPDATE !!

We HAVE to go through a PHP file on the remote server to avoid having to use Remoote MySQL which has to be enabled on an IP basis.

share|improve this question
Code please...? –  netcoder Aug 22 '11 at 20:00
Edited the code... –  Akke Aug 22 '11 at 20:09
Does $row['last_seq'] contains what you're looking for? –  hakre Aug 22 '11 at 20:11
Yes. It does contain what I am looking for. –  Akke Aug 22 '11 at 20:14
I am now doing this via URLProtocol –  Akke Jun 6 '12 at 15:18
add comment

3 Answers

You can call processes that run on the commandline with various function from PHP from the exec familyDocs.

If you're having problems building the actual command string, you can do with:

$cmd = sprintf('c:\myscan %d.pdf', $sequential_number);

As you write that the script is already writing it into the db with the $sequential_number I assume you have it already.

In case the database generates the number, then probably as the primary key. See mysql_insert_idDocs for obtaining the id.

share|improve this answer
add comment

Okay judging by the backslash and the C:\ I am guess you're using windows.

You are going to have to combine the following:


How to store the result of a command expression in a variable using bat scripts?

and then to access the content of the variable you created use the %VARIABLE_NAME% syntax.

share|improve this answer
Very good, very good. But we have to go through a PHP file on the server to avoid using remote MySQL. –  Akke Aug 23 '11 at 4:01
add comment

You should have flag in your mysql table like is_processed with value = 0 or 1. When scan starts it runs query:

SELECT * FROM TABLE where is_processed = 0 order by sec_number

After processing you should run query:

UPDATE TABLE set is_processed = 1 where sec_number = 'sec_processed_number';
share|improve this answer
I am not sure how this relates to what I am trying to do. The trick is to obtain the last used seq number to the command line on the pc. –  Akke Aug 22 '11 at 20:11
add comment

Your Answer


