|
Posted by Raqueeb Hassan on June 25, 2005, 9:11 am
Please log in for more thread options
Hello There!
Have you guys tried inserting variables in mySQL tables? Do I have to
use 'quote' as we had been doing to insert strings?
show/hide quoted text
mysql> INSERT INTO occurrence (word_id,page_id) VALUES
($word_id,$page_id);
ERROR 1054: Unknown column '$word_id' in 'field list'
Thanks in advance.
--
Raqueeb Hassan
Bangladesh
|
|
Posted by Bill Karwin on June 27, 2005, 3:38 pm
Please log in for more thread options
Raqueeb Hassan wrote:
show/hide quoted text
> Hello There!
>
> Have you guys tried inserting variables in mySQL tables? Do I have to
> use 'quote' as we had been doing to insert strings?
>
> mysql> INSERT INTO occurrence (word_id,page_id) VALUES
> ($word_id,$page_id);
> ERROR 1054: Unknown column '$word_id' in 'field list'
There are no variables in the mysql tool identified by the $ symbol.
There is support in the mysql tool for user variables, using the @
symbol. See http://dev.mysql.com/doc/mysql/en/variables.html.
show/hide quoted text
I'm inferring that you're using the mysql tool because of the "mysql>"
prompt you include in your example. If you're talking about using
variables in a perl or php script, then yes, you need to quote string
variables just as you would string literals. No need to quote values
for numeric fields.
Regards,
Bill K.
|
|
Posted by Raqueeb Hassan on June 28, 2005, 7:58 am
Please log in for more thread options show/hide quoted text
> There are no variables in the mysql tool identified by the $ symbol.
> There is support in the mysql tool for user variables, using the @
> symbol. See http://dev.mysql.com/doc/mysql/en/variables.html.
show/hide quoted text
<snip>
Thanks for the reply, Mr. Bill. Basically I was using the idea from
http://www.onlamp.com/pub/a/php/2002/10/24/simplesearchengine.html
and
while inserting the values Author said ...
--------
When building the index, only three SQL INSERT statements actually
matter. When a page is first indexed, it must be recorded:
INSERT INTO page (page_url) VALUES ("http://www.onlamp.com/");
The first occurrence of a word within the entire dataset must be
recorded:
INSERT INTO word (word_word) VALUES ("linux");
Each occurrence of a word within a page must be recorded:
INSERT INTO occurrence (word_id,page_id) VALUES ($word_id,$page_id);
<---- I couldn't do this! As it was generating that previous error.
What might be the cause, please?
-----
Thanks in advance.
Raqueeb Hassan
Bangladesh
|
|
Posted by Bill Karwin on June 28, 2005, 9:53 am
Please log in for more thread options Raqueeb Hassan wrote:
show/hide quoted text
> INSERT INTO occurrence (word_id,page_id) VALUES ($word_id,$page_id);
> <---- I couldn't do this! As it was generating that previous error.
> What might be the cause, please?
Variables with a leading $ are specific to PHP (or Perl, shell, or other
languages that use that kind of identifier). These identifiers have no
meaning to MySQL, but MySQL never sees the variables, only their values.
The technique being shown is to interpolate PHP variables into a string.
Then the string -- with the variables evaluated into their values --
is sent to MySQL to be executed as a SQL statement.
This technique depends on being run in a PHP environment, to do the
variable interpolation. If you are executing the statements in the
mysql command-line tool, you need to provide values literally, or with
the "@foo" type of user variables supplied in the mysql tool.
Regards,
Bill K.
|
|
Posted by Raqueeb Hassan on June 28, 2005, 6:06 pm
Please log in for more thread options show/hide quoted text
> Variables with a leading $ are specific to PHP (or Perl, shell, or other
> languages that use that kind of identifier). These identifiers have no
> meaning to MySQL, but MySQL never sees the variables, only their values.
Thanks Bill. That's how php interpolate variables into a string and
send the values to mysql, as you said. I had been looking for similar
kind of so called "Google Desktop Search SDK", which would index my
drives (windows/linux partitions) with php script to mysql as SWISH-e.
To simply put, I would like to have mysql as backend to a php script
which would index everything like SWISH-e.
Thanks in advance.
--
Raqueeb Hassan
Bangladesh
--
The hardest part about moving forward is not looking back. - Sally
|
| Similar Threads | Posted | | Inserting a list of names in a table using stored procedure | February 20, 2006, 10:02 am |
| Reading Variables available in shell program into MySQL | September 26, 2005, 12:39 am |
| Help with Stored Proc in mysql varchar variables | August 29, 2006, 4:36 am |
| MySQL variables, modifying Microsoft SQL sequence insert for use in mysql | October 7, 2005, 10:54 am |
| Inserting records to MYSQL using ODBC | May 15, 2006, 4:57 pm |
| Macro Variables | April 18, 2006, 11:37 am |
| Declaring variables | June 28, 2006, 4:39 pm |
| Replace variables in resulting query | July 25, 2006, 12:58 pm |
| User defined variables question | July 10, 2007, 8:20 pm |
| inserting unique value | June 21, 2007, 9:20 am |
|