Register a SA Forums Account here!
JOINING THE SA FORUMS WILL REMOVE THIS BIG AD, THE ANNOYING UNDERLINED ADS, AND STUPID INTERSTITIAL ADS!!!

You can: log in, read the tech support FAQ, or request your lost password. This dumb message (and those ads) will appear on every screen until you register! Get rid of this crap by registering your own SA Forums Account and joining roughly 150,000 Goons, for the one-time price of $9.95! We charge money because it costs us money per month for bills, and since we don't believe in showing ads to our users, we try to make the money back through forum registrations.
 
  • Post
  • Reply
Agrikk
Oct 17, 2003

Take care with that! We have not fully ascertained its function, and the ticking is accelerating.
An easy question (probably):


I have a record in a database that contains the < and > characters (Entrails<VP> is the element in question). When I generate an html page based on that data, the interpreter strips them off as an html tag. So:

Entrails
Entrails<VP>

becomes

Entrails
Entrails

causing some confusion.


Without manipulating the data in the database, how can I force PHP to produce a page that displays the <> characters?

Adbot
ADBOT LOVES YOU

Agrikk
Oct 17, 2003

Take care with that! We have not fully ascertained its function, and the ticking is accelerating.
Thanks.

Agrikk
Oct 17, 2003

Take care with that! We have not fully ascertained its function, and the ticking is accelerating.
I am trying to create a PHP applet that will monitor IIS log files (using the tail command) for a specific event and perform an action when that event is found.

I know how to parse a log file when it is written to disk, but how do I do this in such a way that the real time log stream is monitored?

Agrikk
Oct 17, 2003

Take care with that! We have not fully ascertained its function, and the ticking is accelerating.

Munkeymon posted:

I guess you could do this:
php:
<?
$pipe = popen('tail -opt /path/to/logfile','r');
while(!feof($pipe))
{
    //print stuff here
}
fclose($pipe);
?>
That would never close if tail never died, but I guess if thats what you think you want then whatevs.



That's what I want.

We are getting a bunch of SQL injection attacks on our web site, so I want to write a script that pulls the source IP address from the IIS log file as it happens and keep a tally of them per hour.

This seemed the easiest way of doing it.

Agrikk
Oct 17, 2003

Take care with that! We have not fully ascertained its function, and the ticking is accelerating.
I need help breaking up lines of data in a flat file into variable to be imported into a database, and explode() doesn't seem to cut it.

The data that I have is in this format
code:
Depot         1511 A686354-F D Lo Ni             123 Im M4 V
Nubotech      1513 C362556-9   Ni                422 Im F4 III M8 D
Justends Four 1514 D567100-5   Lo Ni             712 Im F8 V M3 D
Ashima        1515 E443942-A   Hi In Po          810 Im G6 V
Koorfagh      1602 E67377B-5                     323 Va M1 V
Gagh Veth     1603 X556423-1   Ni              R 334 Va F2 V
Silibast Ti   1605 E350553-9   Ni Po De          413 Im M5 V F3 V
Khukish       1606 A77A989-F   Hi In Wa Cp       823 Im G9 V
Shishkala     1607 B686654-C   Ag Ni Ri          613 Im A2 V
With the following legend:

1-18: Name
20-23: HexNbr
25-33: UWP (eight sub-variables with a length of 1 each. the hyphen will be omitted)
36: Bases
38-52: Codes & Comments (up to seven sub-variables, space delimted)
54: Zone
57-59: PBG (three sub-variables with a length of one each)
61-62: Allegiance
64-80: Stellar Data (Up to six sub-variables, space delimted)

Explode() will split it up using a delimiter like " ", but what I'd like to do is specify some method where I can grab some characters out of the string of some specific length and stuff it into a variable. The length of the grabbed data varies and will potentially contain spaces in it.

How can I accomplish this?

Agrikk
Oct 17, 2003

Take care with that! We have not fully ascertained its function, and the ticking is accelerating.
How do I insert items randomly into an array of fixed size and avoid collisions?

I have a list of items that I need to insert randomly into an array. The number of items will always be smaller than the size of the array and in the event of a collision I need to pick another random spot in the array.



How can I do this?

Agrikk
Oct 17, 2003

Take care with that! We have not fully ascertained its function, and the ticking is accelerating.

supster posted:

I can almost gaurantee there's a better way to do what you're trying to accomplish. What are you trying to accomplish? shuffle may be what you're looking for.

To pull out the :nerd: hat here, I am writing a script that generates a star system around existing data based on the rules set forth in the MegaTraveller RPG.

I have a database of approximately 50,000 star systems and each system has 1-4 suns, 0-7 gas giants, 0-3 asteroid belts and assorted worlds.

The game's star system generation chapter has a pretty detailed method for generating orbital bodies in a star system and I am automating it using php/mysql.

My current thought is to have an array that represents the orbits of the system and all of the sub orbits (for moons around worlds, binary & trinary systems, etc).

The rules have a complicated method to place suns in a system randomly but with many modifiers, then to place gas giants, then belts, then worlds each with its own set of rules and modifiers. Since an orbit can only contain one object, rerolls are necessary.

Here's the core of what I have so far, but it's broken. It doesn't check if the array is occupied properly, so if the array item is occupied, it gets overwritten buy the incoming record:

code:
<?php

$CompanionOrbitChart = array(0,0,1,2,3,4+rand(1,6),5+rand(1,6),6+rand(1,6),7+rand(1,6),8+rand(1,6),15);


	unset($SystemArray);
	$starcount = rand(1,4);

	//load first star into Array
	$SystemArray[0][0][0] = "Star1";

	//load the rest of the stars
	
	$StarNumber=2;
	while ($StarNumber <= $starcount) 
	{
		do
		{
			$random = (rand(1,6)+(rand(1,6)))-2;
			if ($random > 10) $random = 10;
			$LocationRoll[$StarNumber] = $random;
			
			$CompanionOrbit = $CompanionOrbitChart[$random];
			while (empty($SystemArray[$CompanionOrbit][0][0])) 
			{
				$SystemArray[$CompanionOrbit][0][0] = "Star$StarNumber";
				break 2;
			}
		} while (0);
		$StarNumber++;
	}

	print_r($SystemArray);
?>

Agrikk
Oct 17, 2003

Take care with that! We have not fully ascertained its function, and the ticking is accelerating.

supster posted:

I also just noticed this in your code:
code:
do
{
    ...
} while (0);
Really?

Yeah. The point was to keep rolling and keep trying to find a slot in the array that wasn't filled yet. Once it found an empty slot, it would break out of the loop.

This code snippit was going to be a function that would be called many times for placing stars, gas giants, belts and worlds, and I figured that many rerolls might be necessary in more crowded systems, which is okay with me.

Agrikk
Oct 17, 2003

Take care with that! We have not fully ascertained its function, and the ticking is accelerating.
Two things:

I have this code:

php:
<?
$Size = 0;

if ($Size === "S" || $Size === 0)  $Test =  "S";
if ($Size === "LGG") $Test =  "LGG";
if ($Size === "SGG") $Test =  "SGG";
if ($Size > 0 && $Size <=9)  $Test =  $Size;
if ($Size === "A" )  $Test =  "A";

echo $Test;
?>
Assuming the valid values for $Size are S, LGG, SGG, A and the numbers 0-9, is there a more efficient way of evaluating $Size to produce $Test?

Agrikk fucked around with this message at 07:09 on Sep 18, 2009

Agrikk
Oct 17, 2003

Take care with that! We have not fully ascertained its function, and the ticking is accelerating.
Is there an way to search for the existence of a value in multiple variables at once?


For example, if I have:


$variableone = "do";
$variabletwo = "ray";
$variablethree = "mi";
$variablefour = "fa";
$variablefive = "so";

Is there a function that I can use to search for the existence of "fa" in any of the five variables?


I could easily write a bunch of seperate if/else statements to so this, but I'd like to come up with something a little bit more elegant.

Agrikk
Oct 17, 2003

Take care with that! We have not fully ascertained its function, and the ticking is accelerating.
Good idea. Thanks.

Agrikk
Oct 17, 2003

Take care with that! We have not fully ascertained its function, and the ticking is accelerating.
Why is this code returning "Hello missing"? It should find Hello in the array and thus not return anything.

php:
<?
    $aa = 0;
    do
    {
        $bb = 0;
        do
        {
            $cc = 0;
            do
            {
                $SystemArray[$aa][$bb][$cc]='xx';
                $cc++;
            } while ($cc < 3);
            $bb++;
        } while ($bb < 3);
        $aa++;
    } while ($aa < 3);
    
$SystemArray[0][1][2]='Hello';
    
$str = "Hello";
if (array_search($str, $SystemArray)=== false) echo "\n$str missing\n";

?>

Agrikk
Oct 17, 2003

Take care with that! We have not fully ascertained its function, and the ticking is accelerating.

fletcher posted:

First of all, use for loops. Second of all, $SystemArray only contains 0, 1, 2. It does not contain "Hello". The array $SystemArray[0][1] does contain "Hello" though.

if I do a print_r($SystemArray) I get:

code:
Array
(
    [0] => Array
        (
            [0] => Array
                (
                    [0] => xx
                    [1] => xx
                )

            [1] => Array
                (
                    [0] => xx
                    [1] => xx
                )

        )

    [1] => Array
        (
            [0] => Array
                (
                    [0] => xx
                    [1] => xx
                )

            [1] => Array
                (
                    [0] => xx
                    [1] => Hello
                )

        )

)
Which is expected. "Hello" is in there. What's the best way to verify that is actually is in there?

Agrikk
Oct 17, 2003

Take care with that! We have not fully ascertained its function, and the ticking is accelerating.

Golbez posted:

What does a var_dump($SystemArray) show?

code:
array(2) {
  [0]=>
  array(2) {
    [0]=>
    array(2) {
      [0]=>
      string(2) "xx"
      [1]=>
      string(2) "xx"
    }
    [1]=>
    array(2) {
      [0]=>
      string(2) "xx"
      [1]=>
      string(2) "xx"
    }
  }
  [1]=>
  array(2) {
    [0]=>
    array(2) {
      [0]=>
      string(2) "xx"
      [1]=>
      string(2) "xx"
    }
    [1]=>
    array(2) {
      [0]=>
      string(2) "xx"
      [1]=>
      string(5) "Hello"
    }
  }
}

Agrikk
Oct 17, 2003

Take care with that! We have not fully ascertained its function, and the ticking is accelerating.
So clearly I am doing something wrong and don't understand arrays :argh:

Why doesn't this work?

php:
<?php

//load up multidimensional array with "xx"
    for ($aa=0$aa 2;$aa++)
    {
        for ($bb=0$bb 2;$bb++)
        {
            for ($cc=0$cc 2;$cc++)
            {
                $SystemArray[$aa][$bb][$cc]="xx";
            }
        }
    }
    
//change one element to "Hello"
$SystemArray[1][1][1]="Hello";

//print array to be sure it's there
print_r($SystemArray);

//find "hello"
$IsThere="no";
for ($aa=0$aa 2;$aa++)
{
    for ($bb=0$bb 2;$bb++)
    {
        for ($cc=0$cc 2;$cc++)
        {
            if ($SystemArray[$aa][$bb][$cc]==="Hello"$IsThere="yes";
        }
    }
}

if ($IsThere="no") 
{
    echo "not found\n";
} else {
    echo "found\n";
}


?>
It returns "not found".

Agrikk
Oct 17, 2003

Take care with that! We have not fully ascertained its function, and the ticking is accelerating.

Standish posted:

Also using strings "yes" and "no" instead of booleans is just shameful.

Getting off topic for a second, what does it matter if I use strings or booleans? Is it a performance issue or something?

Agrikk fucked around with this message at 19:43 on Oct 1, 2009

Agrikk
Oct 17, 2003

Take care with that! We have not fully ascertained its function, and the ticking is accelerating.

Standish posted:

It's slower to use strings, yes, but the main thing is style and avoiding horrible bugs like [php]$a = "no";
...
if ($a) // the string "no" converts to the boolean value true![/code]
No, it didn't, the problem was that you had a single '=' instead of a '==' in that line I quoted, so you were assigning $IsThere to "no" instead of checking its value. The reason it started working when you changed to booleans is because the assignment "$IsThere=false" itself evaluates to boolean false, so the if condition failed.

Thanks for your help Standish. I just realized that that was my error. I always get tripped up between =, == and ===. Meh.

Agrikk
Oct 17, 2003

Take care with that! We have not fully ascertained its function, and the ticking is accelerating.
Is there a way other than a set of IF statements that can perform a set of commands depending on what a variable is?

Like if $color is "red" do <command set 1> but if $color is "blue" then do <command set 2> but if $color is "green" do <command set 3>.


I found it. it's the Switch structure.

Agrikk fucked around with this message at 04:48 on Oct 18, 2009

Agrikk
Oct 17, 2003

Take care with that! We have not fully ascertained its function, and the ticking is accelerating.

I have a variable whose values can be anywhere from millions down to ten-thousandths stored in a MySQL database as type Decimal with a length of twelve and four decimal places.

The problem is that when calling them though PHP I end up with results like:
0.3900
0.0001
4500000.0000

I would like the results to appear as:
0.39
0.0001
4,500,000

How can I truncate any zeros after the final digit to the right of the decimal point?

Agrikk fucked around with this message at 19:41 on Jan 12, 2010

Agrikk
Oct 17, 2003

Take care with that! We have not fully ascertained its function, and the ticking is accelerating.

gwar3k1 posted:

Cast the number to a string, check for a decimal point, explode it at the decimal, check each number for avalue higher than 0, if the last number is true then keep it else ignore it.

That's a good one. Thank you.

Edit: Here's what I did:

php:
<?
function TruncateZeros($number)
{
    list($front, $back) = explode(".", $number);
    if ($back <>0){
    $array = array($front,$back);
    $dot_separated = implode(".", $array);
    echo "$dot_separated";
    } else {
    echo "$front";
    }
}
?>
edit: hrm... this worked in a DOS prompt, but not on a web page.

Agrikk fucked around with this message at 02:07 on Jan 13, 2010

Agrikk
Oct 17, 2003

Take care with that! We have not fully ascertained its function, and the ticking is accelerating.
How can I pull windows extended file properties information from a file within PHP?


I am writing a script that organizes photos (.JPGs) based on the date of the picture. However my original attempt uses DIR /OD to call the list of files, however what I need is the metadata "Date Taken" not "Date Created", which makes DIR /OD not what I need.

Agrikk fucked around with this message at 07:10 on Nov 21, 2010

Agrikk
Oct 17, 2003

Take care with that! We have not fully ascertained its function, and the ticking is accelerating.

FeloniousDrunk posted:

You probably want the EXIF data, specifically the FileDateTime I think.

Perfect. THat is exactly what I needed. EXIF.DateTimeOriginal did the trick.

Agrikk fucked around with this message at 05:26 on Nov 22, 2010

Agrikk
Oct 17, 2003

Take care with that! We have not fully ascertained its function, and the ticking is accelerating.
I am connecting to a SQL Server 2014 instance using PHP 5.4.24 and I am trying to figure out why this isn't working:

code:
$version = sqlsrv_query('SELECT @@VERSION');
$row = sqlsrv_fetch_array($version);

echo $row[0];
The connection is established and there are no errors that I can see, but it doesn't return anything. Anyone have any ideas?

Agrikk
Oct 17, 2003

Take care with that! We have not fully ascertained its function, and the ticking is accelerating.

Biowarfare posted:

..also why are you.. why..

Why not?

code:
if( $conn ) {
     echo "Connection established.<br><br>";
}else{
     echo "Connection could not be established.<br />";
     die( print_r( sqlsrv_errors(), true));
}


$sql = "sqlsrv_query('SELECT @@VERSION')";
$result = sqlsrv_query($conn, $sql);

if( $result === false ) {
     die( print_r( sqlsrv_errors(), true));
}
Returns nothing.

Agrikk fucked around with this message at 04:41 on Jun 29, 2015

Agrikk
Oct 17, 2003

Take care with that! We have not fully ascertained its function, and the ticking is accelerating.
This is an AWS / DynamoDB question using PHP, so I'll try here first:

I am working on a PHP script that will load a million rows from a tab delimited text file into DynamoDB every hour. I have worked my way through putItem and batchWriteItem and am now trying to figure out how to make WriteRequestBatch work.


The relevant bit of code I have is:
code:
require 'c://php\sdk\aws-autoloader.php';

use Aws\DynamoDb\DynamoDbClient;
$client = DynamoDbClient::factory(array(
    'profile' => 'default',
    'region'  => 'us-west-2',
    'version' => 'latest'
));
use Aws\DynamoDb\WriteRequestBatch;
$putBatch = WriteRequestBatch::factory($client);
with the $putbatch line coming straight from the AWS documentation here.

When I run this code I receive the following error:

code:
Fatal error: Call to undefined method Aws\DynamoDb\WriteRequestBatch::factory()
Clearly I am doing something wrong but I am not knowledgeable enough with classes, factories and whatnot to make any sense of this error. Can someone help?

Agrikk
Oct 17, 2003

Take care with that! We have not fully ascertained its function, and the ticking is accelerating.

Agrikk posted:

This is an AWS / DynamoDB question using PHP, so I'll try here first:

I am working on a PHP script that will load a million rows from a tab delimited text file into DynamoDB every hour. I have worked my way through putItem and batchWriteItem and am now trying to figure out how to make WriteRequestBatch work.


The relevant bit of code I have is:
code:
require 'c://php\sdk\aws-autoloader.php';

use Aws\DynamoDb\DynamoDbClient;
$client = DynamoDbClient::factory(array(
    'profile' => 'default',
    'region'  => 'us-west-2',
    'version' => 'latest'
));
use Aws\DynamoDb\WriteRequestBatch;
$putBatch = WriteRequestBatch::factory($client);
with the $putbatch line coming straight from the AWS documentation here.

When I run this code I receive the following error:

code:
Fatal error: Call to undefined method Aws\DynamoDb\WriteRequestBatch::factory()
Clearly I am doing something wrong but I am not knowledgeable enough with classes, factories and whatnot to make any sense of this error. Can someone help?

For posterity:

The answer was that while SDK v2's Aws\DynamoDb\Model\BatchRequest\WriteRequestBatch had a factory method, v3's Aws\DynamoDb\WriteRequestBatch does not. I replaced the r line calling that method with this:

code:
$putBatch = new WriteRequestBatch($client);

Agrikk
Oct 17, 2003

Take care with that! We have not fully ascertained its function, and the ticking is accelerating.
Can someone point me to a good resource for learning how to batch insert items into a MySQL database using PHP?


I have a tab-delimited file of 1.1 million rows that I want to insert into a MySQL database (it's actually AWS Aurora) every hour. Most of the examples I find online are of people using arrays to receive the data from the flat file and then using loops to push the data into the database. But iterating over a million-member array one at a time seems dumb and inefficient.

Agrikk
Oct 17, 2003

Take care with that! We have not fully ascertained its function, and the ticking is accelerating.
I am building an IIS-based PHP web site on AWS located in three regions across the globe. On the back end I have a trio of database servers replicating across those regions and I want each pool of web servers to access their local database node above all the others.

I have a single DFS share that spans the three regions so I can make a single code push to the DFS share and all web servers in each of the three pools gets an update.

So I have created a test Config.php file that looks like this:

code:
<?php
echo "Hello<br>";

$OS = getenv('OS');
echo "OS: ".$OS."<br>";

$InstanceAZ = getenv('EC2-InstanceAZ');

if ($InstanceAZ == 'us-west-2a') {$serverName = "10.1.1.50";} 
if ($InstanceAZ == 'us-west-2b') {$serverName = "10.1.1.50";} 
if ($InstanceAZ == 'us-east-1d') {$serverName = "10.2.1.50";} 
if ($InstanceAZ == 'us-east-1e') {$serverName = "10.2.1.50";} 
if ($InstanceAZ == 'us-east-2a') {$serverName = "10.3.1.50";}
if ($InstanceAZ == 'us-east-2b') {$serverName = "10.3.1.50";}
     echo "AZ: ".$InstanceAZ."<br>";
     echo "DB Server: ".$serverName."<br>";

?>
Where EC2-InstanceAZ is a windows system environment variable set at launch via powershell. As it stands right now, I can RDP into a web server, open a command prompt and run the script and it returns

Hello
OS: Windows_NT
AZ: us-west-2a
Server: 10.1.1.50

as expected. But when I run the script by accessing it in IIS I get

Hello
OS: Windows_NT
AZ:
Server:

Somehow PHP is not able to fetch EC2-InstanceAZ from the list of system variables inside IIS even though it can pull a different system variable. Does anyone have an idea?

Agrikk
Oct 17, 2003

Take care with that! We have not fully ascertained its function, and the ticking is accelerating.

nielsm posted:

At what point is your environment variable getting set?

As far as I understand IIS architecture, you run IIS as a system service, which does not inherit any environment, and IIS in turn runs workers such as PHP FastCGI in an application pool, which does not inherit any environment either. So you'd have to configure the environment at the application pool level.

These are AWS EC2 instances, and upon launch they pull AZ information from http://169.254.169.254/latest/meta-data/placement/availability-zone and shoves it into a system variable called EC2-InstanceAZ. I agree about IIS running as a system service, and fast CGI running in a different environment, but System variables should be available to all sessions (as opposed to user variables that are specific to specific sessions).



What is bugging me is that I can pull other system variables (like OS, DriverData) but EC2-InstanceAZ, EC2-InstanceId, etc chokes.

Agrikk fucked around with this message at 20:33 on Dec 9, 2019

Agrikk
Oct 17, 2003

Take care with that! We have not fully ascertained its function, and the ticking is accelerating.

Pile Of Garbage posted:

A few things:

  • Do the variables at least show up in the list displayed by phpinfo()?
  • Are the variables visible in the registry under HKEY_LOCAL_MACHINE\System\CurrentControlSet\Control\Session Manager\Environment?
  • Is IIS being restarted after the variables are set (A child process environment block can only be modified by a parent when the child process is created, therefore changes to parent environment block won't effect the child unless it's restarted)?

The variables do not show up in phpinfo() and they are in the list under Computer\HKEY_LOCAL_MACHINE\SYSTEM\CurrentControlSet\Control\Session Manager\Environment and IIS is being restarted.

itskage posted:

But why??

quote:

Also this, especially the multi-AZ DFS :lol:

Because I have some spare time, and the free resources with which to goof off . And most importantly, because I can. :D

Agrikk
Oct 17, 2003

Take care with that! We have not fully ascertained its function, and the ticking is accelerating.
It turned out to be an IIS thing, not a PHP thing, but the answer was to turn on "Load User Profile" for the application pool.

Agrikk
Oct 17, 2003

Take care with that! We have not fully ascertained its function, and the ticking is accelerating.

a hot gujju bhabhi posted:

Right but for your own sanity why not use a Linux box for PHP and have environment variables just available to you without stuffing around?

I've been a windows guy for decades now. While I can fumble my way around a linux box and make it work, I am way more familiar with the idiosyncrasies of WISP than LAMP (present issue aside). I just don't find Linux boxes intuitive. :shrug:

Agrikk
Oct 17, 2003

Take care with that! We have not fully ascertained its function, and the ticking is accelerating.
Eh, I hear what you are saying and ordinarily I recommend going LAMP to learn PHP, but in this case I’m building a Rube Goldberg setup intentionally.

As it turns out, the back-end is actually a set of databases in three regions including Aurora Postgres, RDS SQL Server, SQL Server Availability Groups and stand-alone but load balanced SQL on EC2. All serving up the same data sets.

So PHP on IIS with the web sites running off of DFS is hardly the weirdest design decision I have going on here. :D

Agrikk
Oct 17, 2003

Take care with that! We have not fully ascertained its function, and the ticking is accelerating.
Looking for memcached help now. Same app as above...


So I have a SQL Server table that is [userID],[timestamp],[data1] and I have a PHP-based web application that returns [data1] for all [timestamp] for a specific [userID]. It returns in a tabular format:

http://folding.rainwalk.net/UserHourlySummary.php?UserName=Agrikk&TeamNumber=33

I'm experimenting with AWS Elasticache to speed up database performance and I'm wondering how to make it all work.

I understand the basic mechanism with PHP that you write a check to see if the key exists in cache then use that, and if it doesn't then fetch it from a database and also copy it into cache.

My question is more around how memcached "knows" that data in the database has been updated.

If the above table receives INSERTS at a rate of one batch every 60 minutes, and data older than 14 days is purged, what is the optimal way to fetch the data in PHP so that data lives in cache for 14 days and what is the optimal way to retrieve the data during page load so that it pulls the majority of the data from cache and the remainder from the database?

Right now my PHP page runs a SELECT statement and then uses a

code:
while( $row = sqlsrv_fetch_array( $stmt) ) {
    echo "<td>".$row[0]->format("Y-m-d H:i")."</td><td>".number_format($row[1])."</td><td>".number_format($row[2])."</td></tr>";
}
statement to build the table for viewing. But a while statement pulls all records in a single batch and I don't see a method to do a check for cache-vs-database existence of each row of data.

What is the best practice here?

Agrikk fucked around with this message at 02:22 on Dec 24, 2019

Agrikk
Oct 17, 2003

Take care with that! We have not fully ascertained its function, and the ticking is accelerating.

joebuddah posted:

What sqlsrv fetch command do I need to use for json data?

The query i am using is


code:
select
x,
y,
tooltip

from
mytable
for json auto
I want to use the results to populate a highchart table.


Ive tried both fetch_array and object. When I use echo to populate the highchart data values.

I don’t understand.

Are you asking how to import a JSON document into SQL Server? Or how to pull data from SQL Server as JSON to consume?

Agrikk
Oct 17, 2003

Take care with that! We have not fully ascertained its function, and the ticking is accelerating.
Can someone help me with a check to see if a row is complete?

I have a file of tab separated values, and some rows are incomplete, which breaks my processing. How can I check to see if the row is incomplete so I can do something else with it?

code:
user1 \t 123 \t data1 \t data2 \n        \\good
user2 \t 634 \t data3 \t data45 \n      \\good
\t 273 \t data7 \t data34 \n             \\bad
984 \t string1 \t string2 \n               \\bad
user3 \t 483 \t data55 \t data78 \n     \\good

Agrikk
Oct 17, 2003

Take care with that! We have not fully ascertained its function, and the ticking is accelerating.
I am bashing my head in over this one.

I am trying to install the php_yaml.dll extension on my windows server (Server 2019 Datacenter v1809) with PHP version 7.0.21 (Thread Safety: Enabled) and I am getting the following error when running php.exe from the command line:

"Warning: PHP Startup: Unable to load dynamic library 'c:\php\ext\php_yaml.dll' - The specified module could not be found."

I have other extensions in the exact same place (c:\php\ext) being accessed the same way (extension=<module>.dll) in c:\PHP\php.ini. I have tested the configuration settings in PHP.ini by renaming an active .dll file which immediately causes the same "Unable to load dynamic library" to show up, so I know the settings are pointing to the right places.

For some reason PHP can't see php_yaml.dll. I have tried php_yaml-2.0.4-7.0-nts-vc14-x64 and php_yaml-2.0.4-7.0-ts-vc14-x64 and php_yaml-2.0.4-7.1-ts-vc14-x64 and they all behave the same way. I even tried php_yaml-2.2.1-7.4-ts-vc15-x64 and got a different error about "the procedure entry point" couldn't be located, which I'm sure has to do with the wrong version of VC14 vs VC15, but at least I know that PHP is looking in the right place for the file.

So why cant PHP find php_yaml.dll?

Agrikk
Oct 17, 2003

Take care with that! We have not fully ascertained its function, and the ticking is accelerating.
Nope. Full control on all the Dlls.

I even tried moving all of my enabled DLLs to a new folder path and all of them work except for the yaml one. :argh:

Agrikk
Oct 17, 2003

Take care with that! We have not fully ascertained its function, and the ticking is accelerating.
Well drat. There's an hour of my life I won't get back.

Turns out that

Biowarfare posted:

see step 5 of https://stackoverflow.com/a/27379895 - this is no longer relevant with the newer versions of php_yaml but since you are on such an old version, this may be why; php_yaml wraps yaml.dll and yaml.dll needs to be available on the path

was the solution. I saw zillions of people saying "add yaml.dll to C:\wamp64\bin\php\phpX\" but I figured that since I was running PHP command line only and not WAMP I didn't need that step. Turns out a better step would be "put yaml.dll somewhere that PATH can see it".

Thanks thread!

FWIW: I'll be upgrading to 8 eventually, but I have so many different workloads running on 7 and I'm afraid that 8 will break things that I hesitate to pull the trigger.

Adbot
ADBOT LOVES YOU

Agrikk
Oct 17, 2003

Take care with that! We have not fully ascertained its function, and the ticking is accelerating.
Follow up on my YAML stuff:

How do I pull elements out of nested PHP (7.0.2) arrays and assign each item to a variable so I can shove the data into a database table?

Given a yaml file like this:
code:
planets:
    40269113:
        celestialIndex: 1
        moons:
            40269114:
                planetAttributes:
                    heightMap1: 3903
                    heightMap2: 3908
                    population: false
                position:
                - -5515163578.0
                - 545177525.0
                - -43874418923.0
            40269115:
                planetAttributes:
                    heightMap1: 3988
                    heightMap2: 3567
                    population: false
                position:
                - -6615163578.0
                - 566177525.0
                - -66874418923.0
        planetAttributes:
            heightMap1: 3842
            heightMap2: 3903
            population: false
        position:
        - -5484995705.0
        - 542195411.0
        - -43853083014.0
    40269116:
        celestialIndex: 2
        moons:
            40269117:
                planetAttributes:
                    heightMap1: 3303
                    heightMap2: 3108
                    population: false
                position:
                - -5515162348.0
                - 545177234.0
                - -43234418923.0
        planetAttributes:
            heightMap1: 3855
            heightMap2: 3955
            population: false
        position:
        - -5484999705.0
        - 542199991.0
        - -43859993014.0
    40269118:
        celestialIndex: 3
        planetAttributes:
            heightMap1: 3246
            heightMap2: 6542
            population: false
        position:
        - -3657999705.0
        - 548765991.0
        - -43859987614.0
radius: 1467665281408.0
regional: true
security: 0.9531232305867214
securityClass: A
solarSystemID: 30000144
solarSystemNameID: 269101
In which a planet can have 0+ moons, how do I parse this information in PHP so that I can dump it into a MSSQL database?

I've managed to parse the file into an array using yaml_parse_file(<filename>) and have pulled the top level stuff and the second level "planet" information using lines like
code:
while($element = current($yaml["planets"])) {
	echo "celestialIndex: ".$yaml["planets"][key($yaml["planets"])]["celestialIndex"]."\n";
	echo "heightMap1: ".$yaml["planets"][key($yaml["planets"])]["planetAttributes"]["heightMap1"]."\n";
	echo "heightMap2: ".$yaml["planets"][key($yaml["planets"])]["planetAttributes"]["heightMap2"]."\n";
	echo "population: ".$yaml["planets"][key($yaml["planets"])]["planetAttributes"]["population"]."\n";
}
but I can't figure out how to perform a while loop inside of a while loop to capture multiple "moon" arrays like I did with the "planets" arrays. I had thought I could just use multiple key entries in nested while loops, but that's not working.

  • 1
  • 2
  • 3
  • 4
  • 5
  • Post
  • Reply