473,473 Members | 2,174 Online
Bytes | Software Development & Data Engineering Community
Create Post

Home Posts Topics Members FAQ

mysql_query

I have a SQL Script with about 5000 SQL Commands.

How can I send it to SQL Server at once?

I see mysql_query() fails on first semicolon (;) who delimits the SQL
Commands.
Another question:
I send to a MySQL server via fast Internet connection, about 500 INSERT
commands one by one via mysql_query().
It takes much time. Why?
I suspect that, mysql_query() after send the query to server, waits for
a "OK" response. If it's true, how can I send and send and send SQL
commands and MySQL server reply "OK" after send all these things?
(or no wait at all?)
Feb 11 '06 #1
5 2906
First of all, you'd better ask in comp.databases.mysql

You can insert more than one row with an insert command:
INSERT INTO tblname(...)
VALUES(...),
(...),
(...);

Depending on the engine used, you could send it without being interested
in the result:
see http://dev.mysql.com/doc/refman/4.1/...t-delayed.html

Best regards

Chameleon wrote:
I have a SQL Script with about 5000 SQL Commands.

How can I send it to SQL Server at once?

I see mysql_query() fails on first semicolon (;) who delimits the SQL
Commands.
Another question:
I send to a MySQL server via fast Internet connection, about 500 INSERT
commands one by one via mysql_query().
It takes much time. Why?
I suspect that, mysql_query() after send the query to server, waits for
a "OK" response. If it's true, how can I send and send and send SQL
commands and MySQL server reply "OK" after send all these things?
(or no wait at all?)

Feb 11 '06 #2
>How can I send it to SQL Server at once?

I don't think you're going to get anywhere using mysql_query to
send to Microsoft SQL Server.
I see mysql_query() fails on first semicolon (;) who delimits the SQL
Commands.
Prior to some version of MySQL (maybe 5.0), you can't send more than
one statement at a time, and it must not have a terminating semicolon.

Even with the latest version, you need to use a client interface
that knows how to deal with multiple result sets coming back.
I am not sure whether PHP does this, but at the least, you need
the mysqli interface, not mysql.
I send to a MySQL server via fast Internet connection, about 500 INSERT
commands one by one via mysql_query().
It takes much time. Why?
I suspect that, mysql_query() after send the query to server, waits for
a "OK" response.
This is the way it's defined to work.
If it's true, how can I send and send and send SQL
commands and MySQL server reply "OK" after send all these things?
(or no wait at all?)


You can insert many, many records with one insert statement,
(even, I believe, on MySQL 3.23.*) e.g.:

insert into table values
(.....),
(.....),
(.....),
(.....);

mysqldump using this form has been known to pack 5,000 records into
one insert statement. You are limited to some buffer size which
might be a quarter of a megabyte or some such limit for the query.

Gordon L. Burditt
Feb 11 '06 #3

"Dikkie Dik" <no****@nospam.org> wrote in message
news:63***************************@news.versatel.n l...
First of all, you'd better ask in comp.databases.mysql

You can insert more than one row with an insert command:
INSERT INTO tblname(...)
VALUES(...),
(...),
(...);
and in MySQL, you are limited to about I think 1MB per insert.(?) so you
must do it in chunks if it's big.


Depending on the engine used, you could send it without being interested
in the result:
see http://dev.mysql.com/doc/refman/4.1/...t-delayed.html

Best regards

Chameleon wrote:
I have a SQL Script with about 5000 SQL Commands.

How can I send it to SQL Server at once?

I see mysql_query() fails on first semicolon (;) who delimits the SQL
Commands.
Another question:
I send to a MySQL server via fast Internet connection, about 500 INSERT
commands one by one via mysql_query().
It takes much time. Why?
I suspect that, mysql_query() after send the query to server, waits for a
"OK" response. If it's true, how can I send and send and send SQL
commands and MySQL server reply "OK" after send all these things?
(or no wait at all?)

Feb 11 '06 #4
Chameleon wrote:
I have a SQL Script with about 5000 SQL Commands.

How can I send it to SQL Server at once?

I see mysql_query() fails on first semicolon (;) who delimits the SQL
Commands.
Another question:
I send to a MySQL server via fast Internet connection, about 500 INSERT
commands one by one via mysql_query().
It takes much time. Why?
I suspect that, mysql_query() after send the query to server, waits for
a "OK" response. If it's true, how can I send and send and send SQL
commands and MySQL server reply "OK" after send all these things?
(or no wait at all?)


A bit late, I know but it got me to thinking....

If you are going to insert 5000 rows into a database once or many times,
sometimes it is achieved much easier by using the LOAD FILE(MySQL), SQL*Loader
(Oracle), RMU/LOAD (Oracle Rdb) or DTS (Data Transformation Service (SQL Server)
to name a few. Use Bulk loaders for bulk load jobs - and life is much
easier... These tools even have exception handling for rows not loaded due to
bad data. You can use the previously stated methods, however, you must remember
to take into account the exceptions.

Exceptions can be:
Bad data (char in num field etc...)
Duplicate data (unique/{primary|foreign} key constraints in the db)
etc...
if one record fails - your entire transaction must be rolled back/undone to
preserve data integrity.

Yes, managing databases and data is quite complicated as the main goal is to
preserve data integrity at all cost. If not, it is not worth a dime to anyone.

my .10 worth :)

--
Michael Austin.
DBA Consultant
Donations welcomed. Http://www.firstdbasource.com/donations.html
:)
Feb 14 '06 #5
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN">

<html>
<head>
<META HTTP-EQUIV="Expires" CONTENT="Tue, 01 Dec 1990 06:30:00 GMT">
<META HTTP-EQUIV="Pragma" CONTENT="no-cache">
<title>Init/Create the DB</title>
</head>

<body>
Query# <div name=i id=i style="font-weight:bold;"></div>
Query: <div name=q id=q style="font-weight:bold;"></div>
<small>
<?php
//init.php
//create the database
include 'databaseinc.php';

//hosting site already has already created the DB
// mysql_create_db($db, $link);
// mysql_select_db($db, $link) or die("db select error: " . mysql_error() .
"<a href=\"kamaniki.php\">Admin Page</a>, <a href=\"index.html\">Main
page</a>");

//read the whole SQL dump file.
//eliminate comments first
$s = file_get_contents("import.sql");
$s = preg_replace($s,"\/\*.*\/\*"); //remove block comments. not a very good
attempt.
$s = preg_replace($s,"^\#.*$"); //remove single-line comments
$a = explode(";",$s);
for ($x=0; $x<count($a); $x++) {
$a[$x]=ltrim(rtrim($a[$x]));
echo "<script>i.innerHTML=$x;q.innerHTML=\"" . addslashes($a[$x]) .
"\";</script>";
if ($a != "" && $a != "\n") {
mysql_query($a) or die("query error: <b>" . mysql_error() . "</b><a
href=\"index.html\">Main page</a>");
}
}
echo "Success...<a href=\"index.html\">Main page</a>";
?>
</small>
</body>
</html>
I created this a while back in the need for database initialization, when
admins had not installed PHPMyAdmin.


"Jim Michaels" <jm******@nospam.yahoo.com> wrote in message
news:Yt********************@comcast.com...

"Dikkie Dik" <no****@nospam.org> wrote in message
news:63***************************@news.versatel.n l...
First of all, you'd better ask in comp.databases.mysql

You can insert more than one row with an insert command:
INSERT INTO tblname(...)
VALUES(...),
(...),
(...);


and in MySQL, you are limited to about I think 1MB per insert.(?) so you
must do it in chunks if it's big.


Depending on the engine used, you could send it without being interested
in the result:
see http://dev.mysql.com/doc/refman/4.1/...t-delayed.html

Best regards

Chameleon wrote:
I have a SQL Script with about 5000 SQL Commands.

How can I send it to SQL Server at once?

I see mysql_query() fails on first semicolon (;) who delimits the SQL
Commands.
Another question:
I send to a MySQL server via fast Internet connection, about 500 INSERT
commands one by one via mysql_query().
It takes much time. Why?
I suspect that, mysql_query() after send the query to server, waits for
a "OK" response. If it's true, how can I send and send and send SQL
commands and MySQL server reply "OK" after send all these things?
(or no wait at all?)


Feb 17 '06 #6

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

Similar topics

4
by: Bruce A. Julseth | last post by:
I know the following $sql will fail since there is no Customer='Smith'. I want to determine how to test a failure of mysql_query. I thought mysql_query returned false if a query failed. The test...
5
by: lkrubner | last post by:
www.php.net says: >>>>>>>>>>>> Only for SELECT,SHOW,EXPLAIN or DESCRIBE statements mysql_query() returns a resource identifier or FALSE if the query was not executed correctly. For other type of...
6
by: aa | last post by:
I use the following fragment of code to output datf from MySQL: ====================================================== $chan = mysql_connect ($db_host, $username, $password); mysql_select_db...
7
by: John Moore | last post by:
Hi I posted three days ago about a function I wrote which kept refusing to run a mysql_query. Well I did away with the function, and hard coded the variables into the query itself. Here's...
3
by: smythe70 | last post by:
How do mysql_query() and mysql_fetch_assoc() actually work? When I submit a query to a MySQL database it goes away, works out what I requested and throws it back at me. When I submit a query...
2
by: techjohnny | last post by:
Error: Warning: mysql_query(): supplied argument is not a valid MySQL-Link resource in /home/jplane/certcent/phpweb/quiz/index.php on line 20 Warning: mysql_num_rows(): supplied argument is...
4
by: atyndall | last post by:
OK, this is the relevant portion script: <?php $username = '__'; // MySQL Database Username. $password = '__'; // MySQL Database Password. $server = '__'; // MySQL Database server (most...
6
by: aerobat | last post by:
hello all just wondering if anyone can help me with this problem. Ii has to do with a simple mysql_query. i have tried so many different ways of doing it, but it wont work. here is the code: ...
5
by: lisles | last post by:
i have a page funtion.php which hs the function to connect to the db /* Mysql Connection */ function connect(){ global $db_server,$db_user,$db_pass,$db;//Global Values from the config.php...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
1
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and...
0
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
0
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated ...
0
muto222
php
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.

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.