Re: running mysql script on website?

  • From: "Humberto Rodriguez" <sub@xxxxxxxxxxxxxxx>
  • To: <programmingblind@xxxxxxxxxxxxx>
  • Date: Thu, 16 Jun 2011 22:25:41 -0400

You could execute all queries, one after the other, if you put them into an 
array and execute a loop.  As to why execute, it is a two-step process, 
mysql_query() prepares the statement and mysql_execute does what its name 
implies.

To create an array with all the queries, so you can avoid repetitive stuff, 
do this:

$queries= array("query1", "query2", "query3", ...);

then:
foreach ($queries as $query) {
mysql_query($query);
mysql_execute;
}

If you were executing something that would retrieve data into memory, you 
would also have to free the results of each query, but it is not necessary 
in this case.

HTH,

Humberto

----- Original Message ----- 
From: "Alex Hall" <mehgcap@xxxxxxxxx>
To: <programmingblind@xxxxxxxxxxxxx>
Sent: Thursday, June 16, 2011 9:10 PM
Subject: Re: running mysql script on website?


|I see, so putting everything in one huge query won't do it; where ever
| I use a semicolon I have to start a new query.
| Why the execute? I thought just doing mysql_query($query) would do it?
| Sorry for all the questions, and thanks for the help.
|
| On 6/16/11, Humberto Rodriguez <sub@xxxxxxxxxxxxxxx> wrote:
| > It is what is called a here-to document, enables you to write text 
without
| > worrying about putting quotes inside quotes, but I think you need a 
space
| > between the <<< and the text that follows, then the same text must be at 
the
| > end, in a separate line, followed by a semicolon.
| >
| > The queries should be made one-at-the-time, and to see what error it
| > produces, do this:
| >
| > mysql_query($query) or die("couldn't run query: " . mysql_error());
| > mysql_execute or die("couldn't execute: " . mysql_error());
| >
| > HTH,
| >
| > Humberto
| >
| > ----- Original Message -----
| > From: "Alex Hall" <mehgcap@xxxxxxxxx>
| > To: <programmingblind@xxxxxxxxxxxxx>
| > Sent: Thursday, June 16, 2011 7:08 PM
| > Subject: Re: running mysql script on website?
| >
| >
| > | Okay, I found out that the three less thans followed by a word are a
| > | neat way to write a lot of text. I now have:
| > | $query= <<<SQL
| > | //my entire sql script, unchanged
| > | SQL;
| > |
| > | However, I get an error in the first line, which is just a bunch of
| > | "drop table if exists <tableName>;" statements. It is running them all
| > | together like one big line, and I guess it wants space between them?
| > | What did I do wrong?
| > |
| > | On 6/16/11, Alex Hall <mehgcap@xxxxxxxxx> wrote:
| > | > I'll probably end up doing this. In your message, the letters EOT
| > | > showed up a couple times, such as:
| > | > $query = <<< EOT
| > | > and then, after the query, they appeared again. What is the syntax
| > | > that should have been there?
| > | >
| > | > On 6/15/11, Humberto Rodriguez <sub@xxxxxxxxxxxxxxx> wrote:
| > | >> What I meant was doing something like this:
| > | >>
| > | >> <?php
| > | >>
| > | >> $link= mysql_connect('host', 'user', 'pass');
| > | >> $query= <<<EOT
| > | >> create table if not exists tablename (
| > | >> ...
| > | >> table definition
| > | >> ...
| > | >> )
| > | >> EOT
| > | >> mysql_query($query);
| > | >> mysql_execute;
| > | >> mysql_close($link);
| > | >> ?>
| > | >>
| > | >> put it in a file with extension .php in your public_html and 
execute it
| > | >> from
| > | >> the browser, then delete it.
| > | >>
| > | >> If the database does not already exist, create it first, with the
| > query:
| > | >> create database databasename
| > | >>
| > | >> HTH,
| > | >>
| > | >> Humberto
| > | >>
| > | >>
| > | >> __________
| > | >> View the list's information and change your settings at
| > | >> //www.freelists.org/list/programmingblind
| > | >>
| > | >>
| > | >
| > | >
| > | > --
| > | > Have a great day,
| > | > Alex (msg sent from GMail website)
| > | > mehgcap@xxxxxxxxx; http://www.facebook.com/mehgcap
| > | >
| > |
| > |
| > | --
| > | Have a great day,
| > | Alex (msg sent from GMail website)
| > | mehgcap@xxxxxxxxx; http://www.facebook.com/mehgcap
| > | __________
| > | View the list's information and change your settings at
| > | //www.freelists.org/list/programmingblind
| > |
| >
| > __________
| > View the list's information and change your settings at
| > //www.freelists.org/list/programmingblind
| >
| >
|
|
| -- 
| Have a great day,
| Alex (msg sent from GMail website)
| mehgcap@xxxxxxxxx; http://www.facebook.com/mehgcap
| __________
| View the list's information and change your settings at
| //www.freelists.org/list/programmingblind
| 

__________
View the list's information and change your settings at 
//www.freelists.org/list/programmingblind

Other related posts: