For example:
There are some quads of subject: "bob".
<bob> <follows> <Jack> .
<bob> <age> <12> .
<bob> <college> <MIT> .
...
Are there any way to get all quads of <bob> ?
Related
I have the following query:
$venues = Venue::select(['id', 'name'])
->where('name', 'LIKE', "%{$query}%")
->orderByRaw("CASE " .
"WHEN name like '{$query}%' THEN 0 " . // start with
"WHEN name like '% {$query}%' THEN 1 " . // start of a later word
"ELSE 3 " .
"END"
)
->limit(5)
->get();
The issue is the above query is vulnerable to SQL injection.
How can I fix this?
Parameter bindings is explained here:
https://laravel.com/docs/5.6/queries#raw-expressions
But if I do:
$venues = Venue::select(['id', 'name'])
->where('name', 'LIKE', "%{$query}%")
->orderByRaw("CASE " .
"WHEN name like '?%' THEN 0 " . // start with
"WHEN name like '% ?%' THEN 1 " . // start of a later word
"ELSE 3 " .
"END",
[
$query,
$query,
]
)
->limit(5)
->get();
I get different results.
Try adding the percent to the query param, like this:
...
->orderByRaw("CASE " .
"WHEN name like ? THEN 0 " . // start with
"WHEN name like ? THEN 1 " . // start of a later word
"ELSE 3 " .
"END",
[
"{$query}%",
"% {$query}%",
]
)
...
So I have many files like this :
The first file :
File1;
Code;1971;1981;1991;2001;2011
A;10;20;30;40;50
B;12;22;32;89;95
...
...
The second file :
File2;
Code;1971;1981;1991;2001;2011
A;1500;1600;460;6000;8000
B;6000;7000;8007;8009;9005
...
...
All Files have the exact same format.
I like to have a table in my database like this :
File Code Year Value
File1 A 1971 10
File1 A 1981 20
File1 A 1991 30
. . .
. . .
File2 A 1971 1500
File2 A 1981 1600
File1 A 1991 460
. . . .
. . . .
File2 B 1971 .
File2 B 1981 .
. . . .
My idea is to creat for each file a t_map in wich we have the file as follow :
My solution with t_map
The problem is that I have so many file like this, and my solution will take me a long time to finish it. Is there any better solution ?
I prefer using PHP to dump all data into MySQL...
Code;1971;1981;1991;2001;2011
A;10;20;30;40;50
B;12;22;32;89;95
after Open & Read file ($file), try this...
<?php
function _T($a){return rtrim(trim($a));}
function _E($a,$b){return explode($a,$b);}
function _S($a,$b,$c){return str_replace($a,$b,$c);}
function _G($a,$b,$c){$d=strpos($a,$b);$e=substr($a,$d);$f=strpos($a,$c);return substr($e,0,($f-$d));}
$file='Code;1971;1981;1991;2001;2011
A;10;20;30;40;50
B;12;22;32;89;95';
$fC=_E('|',_S('Code;','|Code;',$file));
/*Useful with Multiple "Code;" in same file too*/
$fC2=($file).'|';
/* Add "|" to the last */
$fY=array();/*Year*/
$fA=array();/*A*/
$fB=array();/*B*/
$dB=array();/* For Database */
foreach($fC as $fR){
/* Get Year; */
$gY=_E(';',_S('Code;','',_G(_T($fR),'Code;','A;')));
$c=0;foreach($gY as $yR){if(!empty($yR)){/*echo _T($yR).'<br>';*/$fY[$c++]=_T($yR);}}
/* Get A */
$gA=_E(';',_S('A;','',_G(_T($fR),'A;','B;')));
$c=0;foreach($gA as $aR){if(!empty($aR)){/*echo _T($aR).'<br>';*/$fA[$c++]=_T($aR);}}
/* Get B */
$gB=_E(';',_S('B;','',_G(_T($fR),'B;','|')));
$c=0;foreach($gB as $bR){if(!empty($bR)){/*echo _T($bR).'<br>';*/$fB[$c++]=_T($bR);}}
if(empty($fB)){$gB=_E(';',_S('B;','',_G(_T($fC2),'B;','|')));
$c=0;foreach($gB as $bR){if(!empty($bR)){/*echo _T($bR).'<br>';*/$fB[$c++]=_T($bR);}}}
}
/* Show Result */
foreach($fY as $fK=>$fV){
echo $fK.':'.$fV.'='.$fA[$fK].'='.$fB[$fK].'<br>';
$dB[]=array('Year'=>$fV,'A'=>$fA[$fK],'B'=>$fB[$fK]);
}print_r($dB);
?>
Test yourself... :)
i need a regular expression to separate left and right part of this pattern . . . . . :
for e.g.
Media State . . . . . . . . . . . : Media disconnected
Connection-specific DNS Suffix . : alumnus.co.in
Description . . . . . . . . . . . : Microsoft ISATAP Adapter
Physical Address. . . . . . . . . : 00-00-00-00-00-00-00-E0
DHCP Enabled. . . . . . . . . . . : No
Autoconfiguration Enabled . . . . : Yes
and store them into two variable.
i have written this regular expression
regexp {([[a-z]*[0-9]*.*[0-9]*[a-z]*]*" "):([[a-z]*[0-9]*.*[0-9]*[a-z]*]*)} 6*rag5hu. . :4ku5-1a543m match a b
but it is not working.
Any help will be appreciated.
I would do this:
set text {Media State . . . . . . . . . . . : Media disconnected
Connection-specific DNS Suffix . : alumnus.co.in
Description . . . . . . . . . . . : Microsoft ISATAP Adapter
Physical Address. . . . . . . . . : 00-00-00-00-00-00-00-E0
DHCP Enabled. . . . . . . . . . . : No
Autoconfiguration Enabled . . . . : Yes}
foreach line [split $text \n] {
if {[regexp {^(.+?)(?: \.)+ : (.+)$} $line -> name value]} {
puts "$name => $value"
}
}
outputs
Media State => Media disconnected
Connection-specific DNS Suffix => alumnus.co.in
Description => Microsoft ISATAP Adapter
Physical Address. => 00-00-00-00-00-00-00-E0
DHCP Enabled. => No
Autoconfiguration Enabled => Yes
This uses a non-greedy quantifier (+?), and that make every quantifier in the regex non-greedy. You then require the anchors so that the bits you want to capture contain all the text you need.
Borrowing the definition of text:
package require textutil
foreach line [split $text \n] {
lassign [::textutil::splitx [string trim $line] {\s*(?:\. )+:\s*}] a b
puts "a: $a\nb: $b"
}
Giving the output
a: Media State
b: Media disconnected
a: Connection-specific DNS Suffix
b: alumnus.co.in
a: Description
b: Microsoft ISATAP Adapter
a: Physical Address
b: 00-00-00-00-00-00-00-E0
a: DHCP Enabled
b: No
a: Autoconfiguration Enabled
b: Yes
Documentation:
foreach,
lassign,
package,
puts,
split,
string,
textutil (package)
I need to open exim relay to a list of ips in a mysql database.
I think if I can run a script before a email is queued, I can do that. Is there a way?
Mail Enable for windows has a similar solution called "SMTP Inbound Command Scripting".
# configure
. . . . .
hide mysql_servers = localhost/myoneandonlybase/login/pass
hostlist myfriends = ${lookup mysql{SELECT ipaddr FROM submitters}}
. . . . .
acl_smtp_connect = acl_conn
acl_smtp_rcpt = acl_rcpt
acl_smtp_data = acl_data
. . . . .
begin acl
acl_conn:
accept hosts = +myfriends
. . . . .
acl_rcpt:
accept hosts = +myfriends
. . . . .
acl_data:
accept hosts = +myfriends
. . . . .
The default exim configuration file already has a hostlist relay_from_hosts that you can easily populate with an SQL lookup and get the desired result:
hide mysql_servers = localhost/myoneandonlybase/login/pass
hostlist relay_to_domains = ${lookup mysql{SELECT ipaddr FROM submitters}}
Nothing more than that is needed.
I'm trying to get data from a database if a link is clicked.
Basically i have a main.php that contains this:
$sql2="SELECT projectsid, projectname, description,
SUBSTRING(description,0,80) FROM projects";
$result2=mysql_query($sql2);
while($row2 = mysql_fetch_assoc($result2)) {
echo "<div id=\"links\">";
echo "<ul>";
echo "<li> <a href=\"fullproject.php\">" . $row2['projectname'];
$_SESSION['projectname']= $row2['projectname'];
echo "<em>" . $row2['description'] . "</em></a></li>";
echo "</ul>";
echo "</div>";
}
This displays a list of names and a brief description.
Proj1
description
Proj2
description
What i'd like to do is to display the full contents of a project if that one is clicked.
fullproject.php
<?php
session_start();
$projectname= $_SESSION['projectname'];
// Connect to server.
require ("connect.php");
$sql1="SELECT projectsid, projectname, programme, difficult, requirements,
resources, description, contact, gsize, size
FROM projects WHERE projectname = '$projectname'";
$result1=mysql_query($sql1);
while($row1 = mysql_fetch_assoc($result1)) {
echo "Project Name: " . $row1['projectname']. "<br />";
echo "Programme : " . $row1['programme'] . "<br />";
echo "Difficult : " . $row1['difficult'] . "<br />";
echo "Requirements : " . $row1['requirements'] . "<br />";
echo "Resources : " . $row1['resources'] . "<br />";
echo "Description : " . $row1['description'] . "<br />";
echo "Contact : " . $row1['contact'] . "<br />";
echo "Group size : " . $row1['gsize'] . " " . $row1['size'] . "<br />";
echo "<br /> ";
}
Whenever I click any of the project list items, it only displays the last itemin the list.
I believe this is happening because when the while loop ends the session variable is set to the last one.
Can someone tell me how to fix this?
Thanks
Try using GET variable instead of session
in main.php use
echo "<li> <a href='fullproject.php?projectname=$row2[projectname]'>";
in fullproject.php declare a variable and initialize it to the get variable
$projectname= $_GET['projectname'];
There is a lot wrong with this code.
1) You are trying to send the primary key of the table via 2 different methods in main.php: in the session and via the path of the URL. This is just bad practice - the reason you have access to different conduits for passing data is that they all have different semantics, but even then, sending the same thing twice then there's always going to be a risk that the receiving end may see different values and must terefore have a way of reconciling the discrepancy.
2) You are using the session to pass a transactional data item. This is a bad idea - the data item relates to a specific transition - not to the session. $_SESSION should only be used for storing data relating to the sesion - not to navigation or transactions.
3) The other conduit you provided for passing the data item is by appending it to the path within the URL. While in some circumstances this approach has benefits it also has complications specific to the webserver the code is implemented on - you've not provided any explanation of why you are using this apporach instead of a conventional $_GET or $_POST var.
The reason your code is failing is because you can only store a single value in $_SESSION['projectname']. Even if you stored an array of values in the session, there is no mechanism for the webserver to know which of these values was selected when the code was delivered to the browser.
Your HTML is badly structured and poorly formatted too.
The code you've shown does not match the description you've given (it does not display the project name).
Your code is also wide open to SQL injection attacks.
Change it so that in main.php:
echo "<div id=\"links\">\n";
echo "<ul>\n";
while($row2 = mysql_fetch_assoc($result2)){
echo "<li> <a href=\"fullproject.php?project=\""
. urlencode($row2['projectname']) . "\">"
. htmlentities($row2['projectname']) . "</a>\n";
echo "<br /><em>" . $row2['description'] . "</em></li>";
}
echo "</ul>";
echo "</div>";
And in fullproject.php
<?php
session_start();
require ("connect.php");
$projectname= mysql_real_escape_string($_GET['projectname']);
echo"<a href='fullproject.php?project_id='".$row2['project_id'].
"> $row2['projectName']</a>";
in fullproject.php
$project_id=$_GET['project_id'];
then you can use this id to display contents of that project id from database