473,809 Members | 2,842 Online
Bytes | Software Development & Data Engineering Community
+ 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 2922
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.versa tel.nl...
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|foreig n} 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.ph p';

//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.ht ml\">Main
page</a>");

//read the whole SQL dump file.
//eliminate comments first
$s = file_get_conten ts("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.inne rHTML=$x;q.inne rHTML=\"" . addslashes($a[$x]) .
"\";</script>";
if ($a != "" && $a != "\n") {
mysql_query($a) or die("query error: <b>" . mysql_error() . "</b><a
href=\"index.ht ml\">Main page</a>");
}
}
echo "Success... <a href=\"index.ht ml\">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******@nospa m.yahoo.com> wrote in message
news:Yt******** ************@co mcast.com...

"Dikkie Dik" <no****@nospam. org> wrote in message
news:63******** *************** ****@news.versa tel.nl...
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
15774
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 fail path is never taken in the following code is never taken. Also, I get an invalid argument on mysql_num_rows($Result) error message. $sql = "Update Table Set Password='password' where Customer='Smith';
5
8783
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 SQL statements, mysql_query() returns TRUE on success and FALSE on error. A non-FALSE return value means that the query was legal and could be executed by the server. It does not indicate anything about the number of rows affected or returned. It...
6
4674
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 ($DB_name, $chan); $resultid = mysql_query ("select name_ru, description_ru, retail, dealer from lasershot WHERE le='1'", $chan); ........ ======================================================
7
3928
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 what I have now: mysql_query("UPDATE about SET category_id = 58 WHERE about_id = 5") or die('error: ' . mysql_error());
3
5380
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 using PHP I submit the query using mysql_query and then iterate through the result set sing mysql_fetch_assoc() (or mysql_fetch_array() or mysql_fetch_row()). What is the purpose of mysql_fetch_xxxx()? Why can't mysql_query return a two dimensional...
2
16940
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 not a valid MySQL result resource in /home/jplane/certcent/phpweb/quiz/index.php on line 21 PHP CODE:
4
5159
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 likely localhost).
6
10989
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: #include <stdio.h> #include <math.h> #include <string.h> #include <mysql.h> main() {
5
9146
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 $conn = @mysql_connect($db_server,$db_user,$db_pass) or die("Connection to Database Server Failed"); @mysql_select_db($db) or die("Database Selection Failed"); return $conn; }
0
9600
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 effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
0
10633
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. Here is my compilation command: g++-12 -std=c++20 -Wnarrowing bit_field.cpp Here is the code in...
0
10376
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 tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth. The Art of Business Website Design Your website is...
1
10375
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 Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
0
6880
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 then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert into image. Globals.ThisAddIn.Application.ActiveDocument.Select();...
0
5548
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
0
5686
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
4331
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 we have to send another system
3
3011
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...

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.