I am trying to create a version file that will alert the end user if there is an update.
In theory and practical application:
When the admin logs in and goes to their Management interface, a script reads a remote file and compares the remote version with the local version, if they are the same, report that status, if remote is greater, alert.
The local version is pulled from a MySQL table with MySQLi and confirmed to work, the remote file is read, confirmed to work as well how ever I am running into an issue.
Local version is 1.3, remote version is 1.3 yet it reports:
Your Version - 1.3 is OUT OF DATE, new version 1.3 is available for download
When it should say
Your Version is UP TO DATE!
The code I am using is below
require_once('includes/settings.php');
function check_version() {
global $connection;
$query = "SELECT * from version";
$result = mysqli_query($connection, $query);
// if the query fails, die and report
if(!$result = $connection->query($query)){
die('There was an error running the query [' . $connection->error . ']');
}
else {
$row = mysqli_fetch_assoc($result);
$my_version = $row['minor'];
echo '<p>Local = '.$my_version.'</p>';
$ctx = stream_context_create(array(
'http' => array(
'timeout' => 1
)
));
$rversion = file_get_contents("http://www.twedev.com/projects/microcms/version", 0, $ctx);
echo $rversion;
var_dump($rversion);
if ($my_version === $rversion) {
$dev_msg = '<strong>Your Micro CMS Version - '.$my_version.' is CURRENT</strong>';
}
elseif ($my_version != $rversion) {
$dev_msg = '<strong>Your Micro CMS Version - '.$my_version.' is OUT OF DATE,<br> new version '.$rversion.' is available for download</strong>';
}
else {
$dev_msg = '<strong>Something went wrong with the version server</strong>';
}
}
return $dev_msg;
}
?>
What I need is another set of eyes to look through this is point me in the right direction if possible, this has me overly frustrated today.
You are using the === identical operator to compare values, using that instead of == will compare the value and the type of value.
The value you are getting from file_get_contents() it's a string, and the version number seems to be something different to string, probably a float number.
Update: After using var_dump on both vars we could see the result wasn't the same, and the solution was to use trim to strip whitespaces from the end of the string.
Related
My problem is simple. On my website I'm loading several results from MySQL tables inside a while loop in PHP and for some reason the execution time varies from reasonably short (0.13s) or to confusingly long (11s) and I have no idea why. Here is a short version of the code:
<?php
$sql =
"SELECT * FROM test_users, image_uploads
WHERE test_users.APPROVAL = 'granted'
AND test_users.NAME = image_uploads.OWNER
".$checkmember."
".$checkselected."
ORDER BY " . $sortingstring . " LIMIT 0, 27
";
$result = mysqli_query($mysqli, $sql);
$data = "";
$c = 0;
$start = microtime(true);
while($value = mysqli_fetch_array($result)) {
$files_key = $value["KEY"];
$file_hidden = "no";
$inner_query = "SELECT * FROM my_table WHERE KEY = '".$files_key."' AND HIDDEN = '".$file_hidden."'";
$inner_result = mysqli_query($mysqli, $inner_query);
while ($row = mysqli_fetch_array($inner_result)) {
// getting all variables with row[n]
}
$sql = "SELECT * FROM some_other_table WHERE THM=? AND MEMBER=?";
$fstmt = $mysqli->prepare($sql);
$fstmt->bind_param("ss", $value['THM'], 'username');
$fstmt->execute();
$fstmt->store_result();
if($fstmt->num_rows > 0) {
$part0 = 'some elaborate string';
} else {
$part0 = 'some different string';
}
$fstmt->close();
// generate a document using the gathered data
include "../data.php"; // produces $partsMerged
// save to data string
$data .= $partsMerged;
$c++;
}
$time_elapsed_secs = substr(microtime(true) - $start, 0, 5);
// takes sometimes only 0.13 seconds
// and other times up to 11 seconds and more
?>
I was wondering where the problem could be.
Does it have to do with my db connection or is my code flawed? I haven't had this problem at the beginning when I first implemented it but since a few months it's behaving strangely. Sometimes it loads very fast other times as I said it takes 11 seconds or even more.
How can I fix this?
There's a few ways to debug this.
Firstly, any dynamic variables that form part of your query (e.g. $checkmember) - we have no way of knowing here whether these are the same or different each time you're executing the query. If they're different then each time you are executing a different query! So it goes without saying it may take longer depending on what query is being run.
Regardless of the answer, try running the SQL through the MySQL command line and see how long that query takes.
If it's similar (i.e. not an 11 second range) then the answer is it's nothing to do with the actual query itself.
You need to say whether the environment you're running this in is a web server, e.g. accessing the PHP script via a browser, or executing the script via a command line.
There isn't enough information to answer your question. But you need to at least establish some of these things first.
The rule of thumb is that if your raw SQL executes on a MySQL command line in a similar amount of time on subsequent attempts, the problem area is elsewhere (e.g. connection to a web server via a browser). This can be monitored in the Network tab of your browser.
I've this problem with a Sybase IQ database (version SELECT ##version shows Adaptive Server IQ/12.5.0/0306) using the PHP SQL Anywhere extension.
I can't select all rows, i.e. SELECT * from anytable always returns 30 rows.
The only workaround I've found is using SELECT TOP 1000 * from anytable (maximum is 32767) but there are certain situations where I need all rows.
Any help is much appreciated.
EDIT: example script (much like the documentation)
$conn = sasql_connect("HOST=host:port;DBN=dbn;UID=uid;PWD=pwd");
if (!$conn) { echo "Connection failed."; die(); }
$result = sasql_query($conn, "SELECT * FROM dba.anytable" );
sasql_result_all($result); // display 30 rows in a formatted table
sasql_free_result($result);
sasql_disconnect($conn);
EDIT: specs of both machines where I'm experiencing the same exact problem:
Development machine:
Windows 7 x64
PHP 5.4.23 TS x86
SAP SQL Anywhere PHP Module for PHP 5.4
SAP SQL Anywhere Database Client 12.0.1.4134
Production sever:
CentOS 6.6 x64
PHP 5.5.23 NTS (x86_64 as per YUM)
SAP SQL Anywhere PHP Module for PHP 5.5
SAP SQL Anywhere Database Client 12.0.1.4127
Probably a stupid question, but just to be sure.
Did you check in Client --> Tools -> Sybase IQ -> Maximum number of rows to display.
(sry for posting this as an answer, but i dont have enough rep to ask you in comments.) Cheers
Well, there is probably some configurable property somewhere that will release you from the evil clutches of 30. I do not know where that property is. I hope someone finds it.
In case nobody does, however, here is a big hack which orders by the primary key of the given table, retrieves as many rows as it can given your constraints, and keeps track of the last fetched primary key in order to retrieve the next batch of rows. It would be better to adapt this to use START AT or LIMIT / OFFSET if available, but I'm assuming they're not. If one of those is available, you could use this approach for any table. If not, this approach can be adapted to any table which has a unique non-null key.
$conn = sasql_connect("HOST=host:port;DBN=dbn;UID=uid;PWD=pwd");
if (!$conn) {echo "Connection failed."; die(); }
$highest_id = -1;
$num_rows_retrieved = 0;
do {
if (!sasql_real_query($conn, "SELECT TOP 32767 * FROM dba.anytable where anytable_id > $highest_id order by anytable_id")) {
echo "Query failed.";
die();
}
$result = sasql_use_result($conn);
if (!$result) {
echo "No result set.";
die();
}
$num_rows_retrieved = 0;
$num_fields = sasql_num_fields($result);
while ($row = sasql_fetch_row($result)) {
$highest_id = $row[0]; // assumes anytable_id is the first field
$i = 0;
while ($i < $num_fields) {
echo "$row[$i]\t";
$i++;
}
$num_rows_retrieved++;
echo "\n";
}
sasql_free_result($result);
} while ($num_rows_retrieved == 32767);
sasql_disconnect($conn);
I am using this php script to get the result from a simple search query documented here
And I have downloaded this excel file of metadata of property here
$rets_login_url = "http://sef.rets.interealty.com/Login.asmx/Login";
$rets_username = "xxxxxxxx";
$rets_password = "xxxxxxxx";
$rets_user_agent = "PHRETS/1.0";
$rets_user_agent_password = "xxxxxxx";
//////////////////////////////
// start rets connection
$rets = new phRETS;
// Uncomment and change the following if you're connecting
// to a server that supports a version other than RETS 1.5
$rets->AddHeader("RETS-Version", "RETS/1.5");
$rets->AddHeader("User-Agent", $rets_user_agent);
echo "+ Connecting to {$rets_login_url} as {$rets_username}<br>\n";
$connect = $rets->Connect($rets_login_url, $rets_username, $rets_password, $rets_user_agent_password);
// check for errors
if ($connect) {
echo " + Connected<br>\n";
}
else {
echo " + Not connected:<br>\n";
print_r($rets->Error());
exit;
}
$search = $rets->SearchQuery("Property","ResidentialProperty","(ListDate=1990-01-01+)");
while ($listing = $rets->FetchRow($search)) {
echo "Address: {$listing['StreetNumber']} {$listing['StreetName']}, ";
echo "{$listing['City']}, ";
echo "{$listing['State']} {$listing['ZipCode']} listed for ";
echo "\$".number_format($listing['ListPrice'])."\n";
}
$rets->FreeResult($search);
echo "+ Disconnecting<br>\n";
$rets->Disconnect();
when I run this script it shows the result connected and then disconnected. But no result is found. I tried many things suggested on some questions for which result was not showing, But nothing is working for me. Where I am wrong?
My RETS server information are here:
RETS Server: SEF RETS System
RETS System ID: SEFRETS
Login URL: http://sef.rets.interealty.com:80/Login.asmx/Login
RETS Version: 1.5
Server Software: Microsoft-IIS/6.0
I also could not understand what is $rets_modtimestamp_field = "LIST_87";
Please Help me. I need some suggestion over how to get data from the RETS.
The issue is with the parameters in your SearchQuery.
One of the fields in your search query is ListDate. Looking at the attached excel file containing the metadata, "ListDate" is in Column B under StandardNames. The RETS specification uses System Names as default (see below). You need to specify '"StandardNames" => 1' in the options parameter in the SearchQuery function:
$search = $rets->SearchQuery("Property","ResidentialProperty","(ListDate=1990-01-01+)",array("StandardNames" => 1));
Also, check to make sure the second argument, class, of your SearchQuery is correct. To do this you could use the GetMetadataClasses function in PHRETS.
You could also use retsmd.com by logging in with your RETS Server url, username, and password.
The $rets_modtimestamp_field is the field which is a datetime value indicating the date and time when a listing was last modified.
In section 7.4.7 in the RETS 1.7.2 Specification document, http://www.reso.org/assets/RETS/Specifications/rets_1_7_2.pdf,
"Queries may use either standard names or system names in the query (Section 7.7). If the
client chooses to use standard names, it MUST indicate this using the StandardNames
argument...If this entry is set to ("0") or is not present the field names passed in the search are the
SystemNames, as defined in the metadata."
To address your last comment, you need to specify ListingStatus as well, as it is also a required field when running a query. The lookup values for ListingStatus are:
A = Active-Available
B = Backup Contract-Call LA
C = Cancelled
CS = Closed Sale
PS = Pending Sale/Rental
Q = Terminated
T = Temp Off Market
W = Withdrawn
X = Expired
So try something like this instead:
$query ="(922=MIAMI),(246=A)";
Or if you're using standard names:
$query ="(City=MIAMI),(ListingStatus=A)";
And finally:
$search = $rets->SearchQuery("Property", $class, $query, array("StandardNames" => 1, 'Limit' => 10, ));
This should allow you to get some results back at least. Beyond that you can just tweak your query until you get the results you want.
I am trying to query from my table storage by using the Azure SDK for PHP.
My query looks like:
$tableRestProxy = ServicesBuilder::getInstance()->createTableService($this->connectionString);
$filter = "( PartitionKey eq '$id' )";
$options = new QueryEntitiesOptions();
$options->setFilter(Filter::applyQueryString($filter));
$result = $tableRestProxy->queryEntities('test', $options);
$entities = $result->getEntities();
$nextPartitionKey = $result->getNextPartitionKey();
$nextRowKey = $result->getNextRowKey();
while (!is_null($nextRowKey) && !is_null($nextPartitionKey) ) {
$options = new QueryEntitiesOptions();
$options->setNextPartitionKey($nextPartitionKey);
$options->setNextRowKey($nextRowKey);
$options->setFilter(Filter::applyQueryString($filter));
$result2 = $tableRestProxy->queryEntities("test", $options);
$newentities = $result2->getEntities();
$entities=array_merge($newentities, $entities);
}
The issue: When running into the while loop I always get the first 1000 back entities, with the same nextrowkey and nextpartitionkey for each query. Thus it creates an infinit loop.
What am I getting wrong with the continuation of a query?
Any help is appreciated.
#Gaurav: this is true, but occurs only on the second loop (I forgot to add the two lines when posting my code).
I've been trying to find out what's wrong for at least half a day. Finally I got it:
It is due to an older version of the Windows Azure PHP SDK which has a "bug". I stumbled across this "bug" at the bottom of this thread: https://github.com/Azure/azure-sdk-for-php/issues/702
The older version of Windows Azure SDK uses _encodeODataUriValue which seems to be unnecessary.
I am getting this error accessing my site. I have used the same files for three different servers, including my local server and it's running fine. Can someone shed some lights?
$stringIp = $_SERVER['REMOTE_ADDR'];
$intIp = ip2long($stringIp);
$inDB = #mysql_query("SELECT 1 FROM av_whoIsOnline WHERE ip=".$intIp);
if(!mysql_num_rows($inDB)) //CODE IN QUESTION <---------
{
if($_COOKIE['geoData'])
{
list($city,$countryName,$countryAbbrev) = explode('|',mysql_real_escape_string(strip_tags($_COOKIE['geoData'])));
}
else
{
$xml = file_get_contents('http://api.hostip.info/?ip='.$stringIp);
$city = get_tag('gml:name',$xml);
$city = $city[1];
$countryName = get_tag('countryName',$xml);
$countryName = $countryName[0];
$countryAbbrev = get_tag('countryAbbrev',$xml);
$countryAbbrev = $countryAbbrev[0];
setcookie('geoData',$city.'|'.$countryName.'|'.$countryAbbrev, time()+60*60*24*30,'/');
}
$countryName = str_replace('(Unknown Country?)','UNKNOWN',$countryName);
if (!$countryName)
{
$countryName='UNKNOWN';
$countryAbbrev='XX';
$city='(Unknown City?)';
}
Take out the # sign before #mysql_query. This obviously suppresses errors. If you do get an error, $inDB will not be a valid resource, so you will get the error you are getting. Your problem is most likely in the line before.
Also note that the mysql library has been deprecated in favour of mysqli and PDO. Consider changing your code to use one of the newer libraries since they are safer
It's working now. Thanks for the replies.
This was an online script I grabbed from the net awhile back. I've changed host using the same script and got this error. After I uploaded the db, I've deleted any entries in 'av_whoIsOnline'. Then the error occurred. Inserted back the entries and error is gone.
My db connection is located in another file.