CipherIS
asked on
PHP - No data displaing from SQL Server database
Data is not loading from database on PHP page.
How can I troubleshoot data coming from the database?
The headers are displaying but no data underneath.
Database is SQL Server and it is using a Security Certificate. I never added one before.
How can I troubleshoot data coming from the database?
The headers are displaying but no data underneath.
Database is SQL Server and it is using a Security Certificate. I never added one before.
Can you post your query? and use var_dump on your query?
ASKER
Checked HTML. No errors on the page or page source.
Used var_dump on the variable and the value is NULL.
Working on going to the page where the data is obtained and using VAR_DUMP
Question
I have the below
\dir1\index.php
\dir2\api.php
index.php gets the data from api.php. If i put a var_dump in api.php will it return it to index.php page?
Used var_dump on the variable and the value is NULL.
Working on going to the page where the data is obtained and using VAR_DUMP
Question
I have the below
\dir1\index.php
\dir2\api.php
index.php gets the data from api.php. If i put a var_dump in api.php will it return it to index.php page?
ASKER
I'm not getting anything.
<?php
$servername = "xxx.xxx.xxx.xxx";
$database = "xxxxx";
$username = "xxxxxx";
$password = "xxxxxxx";
// Create connection
$conn = new mysqli($servername, $username, $password);
// Check connection
if ($conn->connect_error) {
die("Connection failed: " . $conn->connect_error);
}
echo "Connected successfully";
?>
What do you get if you add var_dump ($conn );
like:
like:
<?php
$servername = "xxx.xxx.xxx.xxx";
$database = "xxxxx";
$username = "xxxxxx";
$password = "xxxxxxx";
// Create connection
$conn = new mysqli($servername, $username, $password);
var_dump ($conn );
// Check connection
if ($conn->connect_error) {
die("Connection failed: " . $conn->connect_error);
}
echo "Connected successfully";
?>
Hi, check your PHP logs and MySQL logs for error
Let say for a local installation using wampserver this will be located in c / wamp64 / logs
you can also enable PHP errors
Ref http://php.net/manual/en/function.error-reporting.php
Let say for a local installation using wampserver this will be located in c / wamp64 / logs
you can also enable PHP errors
<?php
// Turn off all error reporting
error_reporting(0);
// Report simple running errors
error_reporting(E_ERROR | E_WARNING | E_PARSE);
// Reporting E_NOTICE can be good too (to report uninitialized
// variables or catch variable name misspellings ...)
error_reporting(E_ERROR | E_WARNING | E_PARSE | E_NOTICE);
// Report all errors except E_NOTICE
error_reporting(E_ALL & ~E_NOTICE);
// Report all PHP errors (see changelog)
error_reporting(E_ALL);
// Report all PHP errors
error_reporting(-1);
// Same as error_reporting(E_ALL);
ini_set('error_reporting', E_ALL);
?>
Ref http://php.net/manual/en/function.error-reporting.php
ASKER
@rgranlund - I get a NULL
@lenamtl - you want me to run that script?
@lenamtl - you want me to run that script?
Ahhh:
$conn = new mysqli($servername, $username, $password);
You forgot the database.
$conn = new mysqli($servername, $database, $username, $password);
put @lenamtl script at the very top of the page and it will show you all, if any errors.
$conn = new mysqli($servername, $username, $password);
You forgot the database.
$conn = new mysqli($servername, $database, $username, $password);
put @lenamtl script at the very top of the page and it will show you all, if any errors.
Hi,
first check your web server logs
PHP logs and MySQL logs for error
first check your web server logs
PHP logs and MySQL logs for error
ASKER
Where do you check the PHP logs on Ubuntu?
ASKER
Also, it is connecting to SQL Server and not MySQL
I put @lenamtl script on top of page - nothing but nulls for the var_dump
I put @lenamtl script on top of page - nothing but nulls for the var_dump
ASKER
How do I get the value of key?
IF($_SERVER["REQUEST_METHOD"] == "POST"){
$portal_key = (ISSET($_POST["portal_key"]) ? $_POST["portal_key"] : $_COOKIE["portal_key"]);
ECHO(JSON_ENCODE(ms_select_value("EXEC [Portal].[dbo].[SP_ui_modules_fetchAccess] @key='".$portal_key."', @mod='".$_POST["mod"]."';")));
ASKER
I'm looking in the Ubuntu server /var/log/apache2/ and don't see "errors.log" or "php_errors.log"
ASKER
Below is the dbase connection code
<?PHP
$my_default_conn = ARRAY(
"xx.xx.xx.xx",
"xxxxx",
"xxxxx"
);
$ms_default_conn = ARRAY(
"xx.xx.xx.xx",
"xxxx",
"xxxx",
"xxxx"
);
FUNCTION my_select_value($query, $host = NULL, $user = NULL, $pass = NULL){
IF($host == NULL || $user == NULL || $pass == NULL){
GLOBAL $my_default_conn;
$host = $my_default_conn[0];
$user = $my_default_conn[1];
$pass = $my_default_conn[2];
}
$conn = MYSQLI_CONNECT($host, $user, $pass);
$resultrow = MYSQLI_FETCH_ARRAY(MYSQLI_QUERY($conn, $query), MYSQLI_NUM);
MYSQLI_CLOSE($conn);
RETURN $resultrow[0];
}
FUNCTION my_select_table($query, $host = NULL, $user = NULL, $pass = NULL){
IF($host == NULL || $user == NULL || $pass == NULL){
GLOBAL $my_default_conn;
$host = $my_default_conn[0];
$user = $my_default_conn[1];
$pass = $my_default_conn[2];
}
$conn = MYSQLI_CONNECT($host, $user, $pass);
$process = MYSQLI_QUERY($conn, $query);
$resultset = ARRAY();
WHILE($resultrow = MYSQLI_FETCH_ARRAY($process, MYSQLI_NUM)){
$resultset[] = $resultrow;
}
MYSQLI_CLOSE($conn);
RETURN $resultset;
}
FUNCTION my_run_query($query, $host = NULL, $user = NULL, $pass = NULL){
IF($host == NULL || $user == NULL || $pass == NULL){
GLOBAL $my_default_conn;
$host = $my_default_conn[0];
$user = $my_default_conn[1];
$pass = $my_default_conn[2];
}
$conn = MYSQLI_CONNECT($host, $user, $pass);
$resultrow = MYSQLI_QUERY($conn, $query);
MYSQLI_CLOSE($conn);
RETURN $resultrow;
}
FUNCTION my_escape_string($raw){
GLOBAL $my_default_conn;
$host = $my_default_conn[0];
$user = $my_default_conn[1];
$pass = $my_default_conn[2];
$conn = MYSQLI_CONNECT($host, $user, $pass);
RETURN MYSQLI_REAL_ESCAPE_STRING($conn, $raw);
}
FUNCTION ms_select_value($query, $connectionInfo = NULL){
IF($connectionInfo == NULL){
$connstring = $GLOBALS["ms_default_conn"];
$connection = MSSQL_CONNECT($connstring[0], $connstring[1], $connstring[2]);
} ELSE {
$connection = MSSQL_CONNECT($connectionInfo[0], $connectionInfo[1], $connectionInfo[2]);
}
$process = MSSQL_QUERY($query, $connection);
$resultset = MSSQL_FETCH_ARRAY($process);
MSSQL_FREE_RESULT($process);
MSSQL_CLOSE($connection);
RETURN $resultset[0];
}
FUNCTION ms_select_table($query, $server = NULL, $connectionInfo = NULL){
IF($connectionInfo == NULL){
$connstring = $GLOBALS["ms_default_conn"];
$connection = MSSQL_CONNECT($connstring[0], $connstring[1], $connstring[2]);
} ELSE {
$connection = MSSQL_CONNECT($connectionInfo[0], $connectionInfo[1], $connectionInfo[2]);
}
$process = MSSQL_QUERY($query, $connection);
$resultset = ARRAY();
WHILE($resultrow = MSSQL_FETCH_ARRAY($process)){
$resultset[] = $resultrow;
}
MSSQL_FREE_RESULT($process);
MSSQL_CLOSE($connection);
RETURN $resultset;
}
FUNCTION ms_run_query($query, $server = NULL, $connectionInfo = NULL){
IF($connectionInfo == NULL){
$connstring = $GLOBALS["ms_default_conn"];
$connection = MSSQL_CONNECT($connstring[0], $connstring[1], $connstring[2]);
} ELSE {
$connection = MSSQL_CONNECT($connectionInfo[0], $connectionInfo[1], $connectionInfo[2]);
}
$process = MSSQL_QUERY($query, $connection);
$resultset = MSSQL_FETCH_ARRAY($process);
MSSQL_FREE_RESULT($process);
MSSQL_CLOSE($connection);
RETURN $resultset;
}
FUNCTION ms_escape_string($raw){
$raw = STR_REPLACE("'", "''", $raw);
$raw = STR_REPLACE("\0","[NULL]", $raw);
RETURN $raw;
}
?>
ASKER
Below is the error in error.log
[Fri Dec 07 14:47:51.129733 2018] [:error] [pid xxxxx] [client xxx.xxx.xxx.xxx:xxxxx] PHP Notice: Undefined variable: query in /home/webserver/www/xxx.xx xx.com/inc ludes/conn .php on line 2
php_errors.log is empty
[Fri Dec 07 14:47:51.129733 2018] [:error] [pid xxxxx] [client xxx.xxx.xxx.xxx:xxxxx] PHP Notice: Undefined variable: query in /home/webserver/www/xxx.xx
php_errors.log is empty
ASKER
After some troubleshooting I need to find how "p_key is set. This seems to be the prob.
IF($_SERVER["REQUEST_METHOD"] == "POST"){
$p_key = (ISSET($_POST["p_key"]) ? $_POST["p_key"] : $_COOKIE["p_key"]);
Hi,
check if you have the cookies values
Chrome right click inspect / application / cookies
check if you have the cookies values
Chrome right click inspect / application / cookies
ASKER
Thanks.
I figured out the issue. Restarted Apache and that solved it.
I figured out the issue. Restarted Apache and that solved it.
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
I figured out the issue. Restarted Apache and that solved it.
it looks to me that it was a condition which probably not handling well and restarted the Apache server restore the state back to origin.
you may observe if this same error will reoccur in the future.
quick verifications:
1. try check the HTML generated, and see if there's any issues/ errors?
2. check the query and make sure got data being returned?