A nice way to track output of a PHP script when you can’t read an echo is to use a file_put_contents. It generates a logfile.
ex:
file_put_contents(‘my_dump_file2.txt’, var_export($nonEscapedSQL, true));
A nice way to track output of a PHP script when you can’t read an echo is to use a file_put_contents. It generates a logfile.
ex:
file_put_contents(‘my_dump_file2.txt’, var_export($nonEscapedSQL, true));
If you do this, it will say 0 rows affected, even if it actually gets a row to edit.
Opacity ( opacity: .2;) affects the transparency of all the content of a div. If you want to set the background only to be partially transparent, use an RBGA setting instead.’ background: rgba(200, 54, 54, 0.5);'
If you want to see whether an object’s property exists, use
if(myObj.hasOwnProperty("someProperty"))
{ };
When declaring a constant variable, the ‘const’ replaces ‘var’. So:
const NAME_INDEX_FROM_JSON; rather than var const NAME_INDEX_FROM_JSON;.
Derp.
I love var_dump. echo var_dump($array) is the best thing ever for pulling the entire array’s contents in debugging.
In my unfamiliarity with mysqli, I fought with this one a while before figuring out that, no duh, closing the mysqli with mysqli_close($mysqli); destroys the connection and makes subsequent calls (I was logging in, closing, then trying to insert using the same mysqli link) impossible.
Solution: As scripts automatically close database connections when they complete, we don’t technically have to write the close ourselves unless we need to force it to close on long running processes that don’t need the connection to be open for it. But since I’m doing very quick pulls and inserts and no real processing, I can just let the PHP close the connection for me.
the connection resource is automatically destroyed after the processing on a page request ends. To SOLVE, I have to re-require connect.php (my connection to the DB) for each time I send out the req.
foreach ($json_obj as $property=>$values){ //<– Outer loop
//echo “${property} is ${value}”;
foreach ($values as $key => $value){ // <– Variables inside that loop.
echo “$key == $value”;
}
}
I struggled forever trying to figure out the correct way to refer to variables of an include_once or require_once php file from inside a function of anyone PHP class. I got as far as defining global variables…but everything I read seemed to miss one key part, or at least un-emphasize it enough that I missed it: You have to REDECLARE the global variable in the calling PHP before using.
first.php defines a variable with global $puppies.
second.php wants to call that variable in the function CountPuppies. I have to first write my include_once or require_once before that call, then redeclare global $puppies before I do a call like $count = $puppies.
Any tutorials telling you to use commands like mysql_select_DB is out of date. It should all be mysqli stuff now, and you instantiate it at the top of your connect.php with
$mysqli = new mysqli($db_host, $db_username, $db_password, $db_name);
Yeah, that one was fun to figure out.