How include in php works?
I have file a.php and data folder in one folder. In data folder, I create
two files: b.php and c.php. Content of each file
a.php
<?php
$a = 1;
include('data/b.php');
?>
b.php
<?php
include('data/c.php');
?>
c.php
<?php
echo $a;
?>
When I run file a.php, result is 1. But I change content of file b.php to
include('c.php'); the result of file a.php is also 1, I think it it show
an error because file a.php and file c.php is not in one folder. Thank
you.
Sunday, 18 August 2013
Saturday, 17 August 2013
how to pass custom class parameter in myBatis
how to pass custom class parameter in myBatis
//this is my custom Page class
public class Page<T> {
private int pageNo = 1;
private int pageSize = 5;
private int totalRecord;
private int totalPage;
private List<T> results;
//store the query conditon parameter that could be add dynamically
private Map<String, Object> params = new HashMap<String, Object>();
public int getPageNo() {
return pageNo;
}
public void setPageNo(int pageNo) {
this.pageNo = pageNo;
}
public int getPageSize() {
return pageSize;
}
public void setPageSize(int pageSize) {
this.pageSize = pageSize;
}
public int getTotalRecord() {
return totalRecord;
}
public void setTotalRecord(int totalRecord) {
this.totalRecord = totalRecord;
int totalPage = totalRecord%pageSize==0 ? totalRecord/pageSize :
totalRecord/pageSize + 1;
this.setTotalPage(totalPage);
}
public int getTotalPage() {
return totalPage;
}
public void setTotalPage(int totalPage) {
this.totalPage = totalPage;
}
public List<T> getResults() {
return results;
}
public void setResults(List<T> results) {
this.results = results;
}
public Map<String, Object> getParams() {
return params;
}
public void setParams(Map<String, Object> params) {
this.params = params;
}
}
// Mapper XML //here how to get the query parameter value in params (this
is a HashMap in Page Class) select * from vincent_user where name=
#{params.name} and #{params.age}
//test code
@Test
public void findUsersByPage(){
SqlSession sqlSession = sqlSessionFactory.openSession();
try {
UserMapper userMapper = sqlSession.getMapper(UserMapper.class);
Page<User> page = new Page<User>();
page.setPageNo(1);
page.setPageSize(10);
Map<String, Object> params=new HashMap<String, Object>();
params.put("name", "%andy%");
params.put("age", 18);
page.setParams(params);
List<User> users = userMapper.findUsersPage(page);
page.setResults(users);
System.out.println(page);
System.out.println("--------------------------------------------------");
for (User user : users) {
System.out.println(user.getName());
}
} finally {
sqlSession.close();
}
}
//this is my custom Page class
public class Page<T> {
private int pageNo = 1;
private int pageSize = 5;
private int totalRecord;
private int totalPage;
private List<T> results;
//store the query conditon parameter that could be add dynamically
private Map<String, Object> params = new HashMap<String, Object>();
public int getPageNo() {
return pageNo;
}
public void setPageNo(int pageNo) {
this.pageNo = pageNo;
}
public int getPageSize() {
return pageSize;
}
public void setPageSize(int pageSize) {
this.pageSize = pageSize;
}
public int getTotalRecord() {
return totalRecord;
}
public void setTotalRecord(int totalRecord) {
this.totalRecord = totalRecord;
int totalPage = totalRecord%pageSize==0 ? totalRecord/pageSize :
totalRecord/pageSize + 1;
this.setTotalPage(totalPage);
}
public int getTotalPage() {
return totalPage;
}
public void setTotalPage(int totalPage) {
this.totalPage = totalPage;
}
public List<T> getResults() {
return results;
}
public void setResults(List<T> results) {
this.results = results;
}
public Map<String, Object> getParams() {
return params;
}
public void setParams(Map<String, Object> params) {
this.params = params;
}
}
// Mapper XML //here how to get the query parameter value in params (this
is a HashMap in Page Class) select * from vincent_user where name=
#{params.name} and #{params.age}
//test code
@Test
public void findUsersByPage(){
SqlSession sqlSession = sqlSessionFactory.openSession();
try {
UserMapper userMapper = sqlSession.getMapper(UserMapper.class);
Page<User> page = new Page<User>();
page.setPageNo(1);
page.setPageSize(10);
Map<String, Object> params=new HashMap<String, Object>();
params.put("name", "%andy%");
params.put("age", 18);
page.setParams(params);
List<User> users = userMapper.findUsersPage(page);
page.setResults(users);
System.out.println(page);
System.out.println("--------------------------------------------------");
for (User user : users) {
System.out.println(user.getName());
}
} finally {
sqlSession.close();
}
}
Setting a cookie based on query string for split testing
Setting a cookie based on query string for split testing
If a query string is detected, I want to update/set a cookie so a
particular dir is used for that browser session or until the query string
is explicitly set again. Visitor is not to see the dir, but instead will
just see http://mydomain.com/.
This is what I have so far but it doesn't work as expected. Pretty sure
I'm writing the logic wrong, but not sure where.
RewriteCond %{QUERY_STRING} splittest=(A|B)
RewriteRule splittest=(A|B) [CO=splittest:$1:%{HTTP_HOST}:0:/,L]
RewriteCond %{QUERY_STRING} splittest=A [OR]
RewriteCond %{HTTP_COOKIE} splittest=A
# Split test A
RewriteRule ^(.*)$ A/$1 [L]
# Split test B
RewriteRule ^(.*)$ B/$1 [L]
If a query string is detected, I want to update/set a cookie so a
particular dir is used for that browser session or until the query string
is explicitly set again. Visitor is not to see the dir, but instead will
just see http://mydomain.com/.
This is what I have so far but it doesn't work as expected. Pretty sure
I'm writing the logic wrong, but not sure where.
RewriteCond %{QUERY_STRING} splittest=(A|B)
RewriteRule splittest=(A|B) [CO=splittest:$1:%{HTTP_HOST}:0:/,L]
RewriteCond %{QUERY_STRING} splittest=A [OR]
RewriteCond %{HTTP_COOKIE} splittest=A
# Split test A
RewriteRule ^(.*)$ A/$1 [L]
# Split test B
RewriteRule ^(.*)$ B/$1 [L]
How to restart listening Twitter straming Api Again?
How to restart listening Twitter straming Api Again?
I'm using Twitter4j to get Tweets real time via. Twitter streaming API and
it is working fine . Sometime it throws Exception due to network
connecting issue(or some other reason) which is also OK to me however I'm
not able to recover from this condition & it require server restart . Can
someone please suggest how to restart listening Twitter straming Api Again
without server restart . We have TwitterStreamFactory & TwitterStream
class in Twitter4j. Many thanks in advance .
I'm using Twitter4j to get Tweets real time via. Twitter streaming API and
it is working fine . Sometime it throws Exception due to network
connecting issue(or some other reason) which is also OK to me however I'm
not able to recover from this condition & it require server restart . Can
someone please suggest how to restart listening Twitter straming Api Again
without server restart . We have TwitterStreamFactory & TwitterStream
class in Twitter4j. Many thanks in advance .
Questions about STL containers in C++
Questions about STL containers in C++
How often do std::multimap and std::unordered_multimap shuffle entries
around? I'm asking because my code passes around references to distinguish
between entries with the same hash, and I want to know when to run the
reference redirection function on them.
What happens if I do this:
std::multimap Table; //Tyype specification stuff left out
//Code that pus in two entries with the same key, call that key foo
int bar = Table[foo];
Is the result different if it's an unordered_multimap instead?
Back to passing references around to distinguish entries with the same
hash. Is there a safer way to do that?
How often do std::multimap and std::unordered_multimap shuffle entries
around? I'm asking because my code passes around references to distinguish
between entries with the same hash, and I want to know when to run the
reference redirection function on them.
What happens if I do this:
std::multimap Table; //Tyype specification stuff left out
//Code that pus in two entries with the same key, call that key foo
int bar = Table[foo];
Is the result different if it's an unordered_multimap instead?
Back to passing references around to distinguish entries with the same
hash. Is there a safer way to do that?
URL rewrite not working in CodeIgniter hosted with dreamhost
URL rewrite not working in CodeIgniter hosted with dreamhost
So I've gone through dozens of forum posts and websites between dreamhost,
codeingiter etc. I have a file directory set up in codeigniter hosted on
dreamhost as follows: mysite.com > application|system|user_guide|.htaccess
the live site i can access is mysite.com/index.php/site/WhatIwantToKeep
my .htaccess file reads:
RewriteEngine on
RewriteBase /
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^(.*)$ /index.php?/$1 [L]
Currently if i go to mysite.com/site/WhatIwantToKeep it can't find it. If
i place any IfModule tags or options lines, it gives a server 500 error.
Ideally this code would rewrite it so that my urls would be reading:
mysite.com/WhatIwantToKeep
Thanks!
So I've gone through dozens of forum posts and websites between dreamhost,
codeingiter etc. I have a file directory set up in codeigniter hosted on
dreamhost as follows: mysite.com > application|system|user_guide|.htaccess
the live site i can access is mysite.com/index.php/site/WhatIwantToKeep
my .htaccess file reads:
RewriteEngine on
RewriteBase /
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^(.*)$ /index.php?/$1 [L]
Currently if i go to mysite.com/site/WhatIwantToKeep it can't find it. If
i place any IfModule tags or options lines, it gives a server 500 error.
Ideally this code would rewrite it so that my urls would be reading:
mysite.com/WhatIwantToKeep
Thanks!
PHP - MySQL - How to check if value updated or not
PHP - MySQL - How to check if value updated or not
I have a php code to update / change value of already existing record like;
$con = mysql_connect("server","username","password");
if (!$con){
die('Could not connect: ' . mysql_error());
}
mysql_select_db("database", $con);
$query = mysql_query("UPDATE table SET field1='$newvalue1',
field2='$newvalue2' WHERE key = '$key'") or exit(mysql_error());
echo "true";
I want to echo "true" if data is updated and echo "false" if there is some
syntax error or if record don't exist or something else, where record
value remain unchanged. How can I do this?
Note: I know mysqli* and I prefer it over mysql*, but here for traditional
mysql*
Thanks in advance...:)
I have a php code to update / change value of already existing record like;
$con = mysql_connect("server","username","password");
if (!$con){
die('Could not connect: ' . mysql_error());
}
mysql_select_db("database", $con);
$query = mysql_query("UPDATE table SET field1='$newvalue1',
field2='$newvalue2' WHERE key = '$key'") or exit(mysql_error());
echo "true";
I want to echo "true" if data is updated and echo "false" if there is some
syntax error or if record don't exist or something else, where record
value remain unchanged. How can I do this?
Note: I know mysqli* and I prefer it over mysql*, but here for traditional
mysql*
Thanks in advance...:)
Subscribe to:
Posts (Atom)