MESSAGE
DATE | 2015-01-29 |
FROM | Ruben
|
SUBJECT | Re: [LIU Comp Sci] Operating System Interupts
|
From owner-learn-outgoing-at-mrbrklyn.com Thu Jan 29 22:20:29 2015 Return-Path: X-Original-To: archive-at-mrbrklyn.com Delivered-To: archive-at-mrbrklyn.com Received: by mrbrklyn.com (Postfix) id 555F31612E4; Thu, 29 Jan 2015 22:20:29 -0500 (EST) Delivered-To: learn-outgoing-at-mrbrklyn.com Received: by mrbrklyn.com (Postfix, from userid 28) id 4079D1612E7; Thu, 29 Jan 2015 22:20:29 -0500 (EST) Delivered-To: learn-at-mrbrklyn.com Received: from mail-qa0-f47.google.com (mail-qa0-f47.google.com [209.85.216.47]) by mrbrklyn.com (Postfix) with ESMTP id 6BAC51612E4 for ; Thu, 29 Jan 2015 22:20:28 -0500 (EST) Received: by mail-qa0-f47.google.com with SMTP id n8so18361053qaq.6 for ; Thu, 29 Jan 2015 19:20:27 -0800 (PST) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20130820; h=x-gm-message-state:message-id:date:from:user-agent:mime-version:to :subject:references:in-reply-to:content-type :content-transfer-encoding; bh=AZ4/C6nIsXkfmteGGFBzdl2cqnzkKMEcxgJyA8cN/Ng=; b=BzdXiLykc/aJqyEdQYyxKDuOLwWn7E6AHZaOgehfvDkxN0xZMGdBWAhJuXar0VzotO aneB5qTka7tKXZ9AqVQ9acx/J1DBkPCHovWq3dRQnB80Bp8BIIXddPYkf9m/10bYaGoc rOhRGvBKfE8kFtDFU0azYCwexupmN1aaasJDu3HX6IZtKgYvq+3MxnTw5q6FueblVnZJ wcQEI7ttW/tUsEktVbRVZpghdkLUQiWsrYommtTw5gCuuoivMBR/JSwCkvt+1ztra8IH oso9ZXx3k+txnlHxVMgZbtkh3jmGGoTy+8+Miky7UwaVzoz/HYD9Qd2yHeUd+vUtQCYO 8Blg== X-Gm-Message-State: ALoCoQkoXU83ia8effgAciDn+c+M5Azzpm6aSCdUR7RUY3p+ae9U/yaJMnc3IeB6P1xImt0M0p+v X-Received: by 10.229.249.137 with SMTP id mk9mr8492641qcb.4.1422588027619; Thu, 29 Jan 2015 19:20:27 -0800 (PST) Received: from [10.0.0.19] ([96.57.23.82]) by mx.google.com with ESMTPSA id 11sm8858796qgt.41.2015.01.29.19.20.27 for (version=TLSv1.2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Thu, 29 Jan 2015 19:20:27 -0800 (PST) Message-ID: <54CAF87A.2070505-at-my.liu.edu> Date: Thu, 29 Jan 2015 22:20:26 -0500 From: Ruben User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:31.0) Gecko/20100101 Thunderbird/31.3.0 MIME-Version: 1.0 To: learn-at-mrbrklyn.com Subject: Re: [LIU Comp Sci] Operating System Interupts References: <54CAAE57.1030900-at-panix.com> <54CAF652.5050609-at-panix.com> In-Reply-To: <54CAF652.5050609-at-panix.com> Content-Type: text/plain; charset=utf-8 Content-Transfer-Encoding: 7bit Sender: owner-learn-at-mrbrklyn.com Precedence: bulk Reply-To: learn-at-mrbrklyn.com
FWIW - Here is Lew in action You won't find this in the database class, that is for sure...
https://groups.google.com/forum/#!topic/comp.databases.mysql/zCfMAXjDJA0
richard 6/19/14
Thanks for the code. It works fine except one or two things. where a field contains a single quote, an error is generated.
Warning: mysqli_error() expects exactly 1 parameter, 0 given
Cant INSERT into table tracker, key=07-11-2014 60-003, asid=60-003. MySQL error : Cathy's Clown...Everly Brothers, The Warning: mysqli_errno() expects exactly 1 parameter, 0 given
All other entries produce the parameter error as well.
As for the date thing, I have decided to use the Julian calendar rather than the Gregorian.Makes sorting easier.
BTW, in the $iresult section, you showed each new line beginning with ." Not needed in php.
if ($con=mysqli_connect("localhost","","","")) { $dt = "07-11-2014"; for ($n = 0; $n < 100; ++$n) { $asid = sprintf("60-%03u",$n); $key = sprintf("%s %s",$dt,$asid); if ($result = mysqli_query($con,"SELECT * from sixty where sid = '$asid'")) { $row = mysqli_fetch_assoc($result); printf("%s...%s $t = $row['title']; $a = $row['artist']; if (empty($a)) $a='x'; $iresult = mysqli_query($con,"INSERT INTO tracker (event,date,songID,track,artist,hits) VALUES ('$key','$dt','$asid','$t','$a',1) ON DUPLICATE KEY UPDATE hits=hits+1"); if (!$iresult) printf("Cant INSERT into table tracker, key=%s, asid=%s. MySQL error %s: %s", $key, $asid, mysqli_errno(), mysqli_error()); } else printf("Cant SELECT from table sixty, sid %s. MySQL error %s: %s", $asid, mysqli_errno(), mysqli_error()); } mysqli_close($con); } else printf("Failed to connect to MySQL: Error %s: %s", mysqli_errno(),mysqli_error()); Doug Miller 6/19/14
richard > wrote in news:1wxtk83sxy8qy$.131kkds0czpxy.dlg-at- 40tude.net :
> Thanks for the code. It works fine except one or two things. > where a field contains a single quote, an error is generated.
So fix it. Sheesh. He warned you that it was untested. > > > Warning: mysqli_error() expects exactly 1 parameter, 0 given > > Cant INSERT into table tracker, key=07-11-2014 60-003, asid=60-003. MySQL > error : Cathy's Clown...Everly Brothers, The Warning: mysqli_errno() > expects exactly 1 parameter, 0 given
That's a pretty clear description of the problem, isn't it?
Lew, dontcha just love the way he's practically demanding that you fix something you gave him for free? "ATTN: Lew Pitcher" Lew Pitcher 6/19/14
On Thursday 19 June 2014 09:18, in comp.databases.mysql, "richard" > wrote:
> Thanks for the code. It works fine except one or two things. > where a field contains a single quote, an error is generated. > > Warning: mysqli_error() expects exactly 1 parameter, 0 given
Oops. Looks like I goofed, when I changed your calls from mysqli_connect_error()/mysqli_conect_errno() to mysqli_error()/mysql_connect_errno().
The connection failure case /should/ use mysqli_connect_*() (as you had them), and not mysqli_*() (as I had them). Please see /*C*/ in the code below.
The other mysqli_ failures should use mysqli_error()/mysqli_errno() as I had intended, but with the connection parameter specified (which I missed). Please see /*B*/ in the code below.
> Cant INSERT into table tracker, key=07-11-2014 60-003, asid=60-003. MySQL > error : Cathy's Clown...Everly Brothers, The Warning: mysqli_errno() > expects exactly 1 parameter, 0 given
This would be because none of the source data fields were "escaped". This is the same as the original code you posted. On writing to the database (INSERT/UPDATE), you (we) need to "sanitize" input data to ensure that the data will not interfere with the SQL (unescaped quotes, for instance, causing premature closing of quoted fields). You do this by first passing the data through the mysqli_real_escape_string() function, before passing it to the query or bind. See http://www.php.net/manual/en/mysqli.real-escape-string.php for details. Also, see /* A */ in the code below
> All other entries produce the parameter error as well. > > As for the date thing, I have decided to use the Julian calendar rather > than the Gregorian.Makes sorting easier. > > BTW, in the $iresult section, you showed each new line beginning with ." > Not needed in php. > > > if ($con=mysqli_connect("localhost","","","")) > { > $dt = "07-11-2014"; > > for ($n = 0; $n < 100; ++$n) > { > $asid = sprintf("60-%03u",$n); > $key = sprintf("%s %s",$dt,$asid); > > if ($result = mysqli_query($con,"SELECT * from sixty where sid = > '$asid'")) > { > $row = mysqli_fetch_assoc($result); > printf("%s...%s
/* A ** changed from straight assignment to assignment through ** mysqli_real_escape_string() */ $t = mysqli_real_escape_string($con,$row['title']); $a = mysqli_real_escape_string($con,$row['artist']); > if (empty($a)) $a='x';
> $iresult = mysqli_query($con,"INSERT INTO tracker > (event,date,songID,track,artist,hits) > VALUES > ('$key','$dt','$asid','$t','$a',1) > ON DUPLICATE KEY UPDATE hits=hits+1"); > > if (!$iresult) printf("Cant INSERT into table tracker, key=%s, > asid=%s. MySQL error %s: %s", // $key, $asid, mysqli_errno(), mysqli_error()); /*B*/ $key, $asid, mysqli_errno($con), mysqli_error($con));
> > } > > else printf("Cant SELECT from table sixty, sid %s. MySQL error %s: > %s", // $asid, mysqli_errno(), mysqli_error()); /*B*/ $asid, mysqli_errno($con), mysqli_error($con)); > } > > mysqli_close($con); > } > else printf("Failed to connect to MySQL: Error %s: %s", // mysqli_errno(),mysqli_error()); /*C*/ mysqli_connect_errno(), mysqli_connect_error());
-- Lew Pitcher "In Skills, We Trust" PGP public key available upon request
Lew Pitcher 6/19/14
On Thursday 19 June 2014 09:31, in comp.databases.mysql, "Doug Miller" - show quoted text - I fix what I break. He has a valid argument for asking.
Of course, he /could/ take the initiative, find and fix the problems, and be one up on me here. :-) - show quoted text - Lew Pitcher 6/19/14
On Thursday 19 June 2014 09:18, in comp.databases.mysql, "richard" > wrote:
> Thanks for the code. It works fine except one or two things. [snip]
Richard,
If you would like to discuss this offline, you can always email me. - show quoted text - Doug Miller 6/19/14
Lew Pitcher > wrote in news:zTBov.4706$Id2.1366-at-fx05.iad:
> On Thursday 19 June 2014 09:31, in comp.databases.mysql, "Doug Miller" > > wrote: >> Lew, dontcha just love the way he's practically demanding that you fix >> something you gave him for free? "ATTN: Lew Pitcher" > > I fix what I break. He has a valid argument for asking.
I don't understand why you're helping him at all -- history tells us that he is not capable of learning, and will be back next week with another problem -- but of course that's your affair. richard 6/19/14
- show quoted text - Trust me, I tried fixing it. Problem being that there are to many variables to figure out which one is the correct paramater. richard 6/19/14
Thanks. It all works just fine now.
I've seen various codes for "sanitizing" strings, yours is so far the cleanest and most straight forward approach. I believe I have learned a few new tricks here. Lew Pitcher 6/19/14
On Thursday 19 June 2014 10:16, in comp.databases.mysql, "richard" > wrote:
> > Thanks. It all works just fine now. > > I've seen various codes for "sanitizing" strings, yours is so far the > cleanest and most straight forward approach.
Not mine, but thanks for the credit.
This is just a standard part of the mysqli API to MySQL, provided for exactly this purpose.
> I believe I have learned a few new tricks here.
Perhaps this is a good thing :-) - show quoted text - Denis McMahon 6/19/14
On Thu, 19 Jun 2014 10:08:49 -0400, richard wrote:
> Problem being that there are to many variables to figure out which one > is the correct paramater.
If you read the function help for mysqli_error(). i's pretty obvious what it expects for the parameter.
-- Denis McMahon, denismf...-at-gmail.com
|
|