I'm new in raspberry and I'm trying to read a simple database from a php page but there is something wrong: I can't read the database content: Here the php page code:
<!DOCTYPE html>
<html>
<body>
<H1>Test Database</H1>
<?php
$sq = sqlite_open('miodatabase.db', 0666, $sqlite_error);
if(!$sq)
{
die(“Errore Sqlite: “.$sqlite_error);
}
$result = sqlite_query($sq, 'select * from test');
while($data = sqlite_fetch_array($result))
{
echo $data[‘nome’];
}
sqlite_close($sq);
?>
</body>
</html>
The database is "miodatabase" that contains a table called "test". I put the database in \var\www\html folder (is correct?) but when I open the page I see a blank page. I'm sure the database contains the table (tested with sqlite3 commands) and the table contains one row. Where I need to put the database? Why I can't see nothing? Thanks
If you don't see anything, i think it's a php configuration issue.
Did you try to add :
<?php phpinfo(); ?>
at the beginning of your script. If you have blank page, look your apache/nginx configuration.
You can also try to run your script from the command line. Maybe helpful in some case.
UPdate
If you use SQLite3 follow this code
class MyDB extends SQLite3
{
function __construct()
{
$this->open('miodatabase.db');
}
}
$db = new MyDB();
$result = $db->query('select * from test', SQLITE3_OPEN_READWRITE );
//var_dump($result->fetchArray());
while($data = $result->fetchArray())
{
echo $data[‘nome’];
}
$db->close();
I solved: I type again the command
sudo apt-get install php5-sqlite
sudo /etc/init.d/apache2 restart
and then I can see in the php info the sections about sqlite3.
The I update my php page like this:
//Enable show error
ini_set('display_errors', 'On');
error_reporting(E_ALL|E_STRICT);
$db = new SQLite3("miodatabase.db");
$sql_select='SELECT * FROM test';
$result=$db->query($sql_select);
echo "<table border='1'>";
echo "<tr>";
$numColumns=$result->numColumns();
for ($i = 0; $i < $numColumns; $i++)
{
$colname=$result->columnName($i);
echo "<th>$colname</th>";
}
echo "</tr>";
while($row = $result->fetchArray(SQLITE3_NUM))
{
echo "<tr>";
for ($i = 0; $i < $numColumns; $i++)
{
$value=$row[$i];
echo "<th>$value</th>";
}
echo "</tr>";
}
echo "</table>";
To open the database I use now
$db = new SQLite3("miodatabase.db");
because the sqlite_open is not supported by this version of sqlite.
Now all works correctly
Related
I am debugging an open source PHP software (not a free one) for a client of mine.
It's a cashier software.
They have an issue with a document containing 748 lines.
When trying to display the document, PHP crashes and the user have to wait for the timeout.
It crashes on that echo (not the affichageUneLigne function, but really on the echo):
while ($r_sql = mysql_fetch_array($result)) {
echo affichageUneLigne($conn_mag, $r_sql, $typePRIX, $articleTEMPS, $clienDe, $caissier, $themeCAISSE, $provenance);
print '<div id="clearer"></div>';
$cptLIGNE++;
}
When I do that:
while ($r_sql = mysql_fetch_array($result)) {
if ($r_sql['DL_Ligne'] < 6360000){
echo affichageUneLigne($conn_mag, $r_sql, $typePRIX, $articleTEMPS, $clienDe, $caissier, $themeCAISSE, $provenance);
print '<div id="clearer"></div>';
$cptLIGNE++;
}
}
or that:
while ($r_sql = mysql_fetch_array($result)) {
if ($r_sql['DL_Ligne'] >= 6360000){
echo affichageUneLigne($conn_mag, $r_sql, $typePRIX, $articleTEMPS, $clienDe, $caissier, $themeCAISSE, $provenance);
print '<div id="clearer"></div>';
$cptLIGNE++;
}
}
It works. (Knowing that DL_Ligne is the line number with a step of 1000.)
I tought of a buffer length problem, but ob_flush before that line doesn't solve it, nor does it by increasing the memory_limit parameter.
PS: Do not ask me chy the developpers of this software have mixed echo and print, it's like that everywhere in the code...
What happens if you do something like this?
<?php
$outputArray = [];
while ($r_sql = mysql_fetch_array($result)) {
$outputArray[] = affichageUneLigne($conn_mag, $r_sql, $typePRIX, $articleTEMPS, $clienDe, $caissier, $themeCAISSE, $provenance);
$cptLIGNE++;
}
$outputString = implode('<div id="clearer"></div>', $outputArray);
echo $outputString . '<div id="clearer"></div>';
I have an Apache server on my Mac but I recently got a PC so I'm moving my code over to it.
On my mac this code works:
db.php:
<?php
$url = "127.0.0.1";
$user = "username";
$pass = "password";
$conn = mysqli_connect("$url","$user","$pass","space");
?>
index.php
<html>
<head>
<?
include 'db.php';
?>
<!-- Header stuff -->
</head>
<body>
<!-- Body stuff -->
<?php
$spaceSelect = mysqli_query($conn, "SELECT * FROM `world`");
$i = 1;
while($space = mysqli_fetch_array($spaceSelect)){
echo "<button id='sector' data-toggle='modal' data-target='#".$space['id']."Modal'>".$space['id']."</button>";
$i += 1;
if($i % 10 == 1){
echo "<br>";
};
echo "stuff";
};
?>
</body>
</html>
When I run this on the new server I get the error
Notice: Undefined variable: conn in S:\shared\space\index.php on line 30
This fixes if I move "include db.php"
index.php
<html>
<head>
<?
?>
<!-- Header stuff -->
</head>
<body>
<!-- Body stuff -->
<?php
include 'db.php';
$spaceSelect = mysqli_query($conn, "SELECT * FROM `world`");
$i = 1;
while($space = mysqli_fetch_array($spaceSelect)){
echo "<button id='sector' data-toggle='modal' data-target='#".$space['id']."Modal'>".$space['id']."</button>";
$i += 1;
if($i % 10 == 1){
echo "<br>";
};
echo "stuff";
};
?>
</body>
</html>
This is really annoying me and I wasn't getting this error when the server was on my Mac. Is there something I need to change in httpd.conf?
1st : Find the php.ini file and
You should find a line that says
short_open_tag = Off
change this to:
short_open_tag = On
If the line doesn't exist just add it.
2nd : After editing php.ini file restart the apache service
try a include_once in the header section. Normally, changes in the httpd.conf are only needed if you use sub folders.
Link to my project:
http://www.mediafire.com/download/1ebozib6qdq2obd/Delivery4All.rar
Basically when i try to open displaymenus.php my php code doesn't get executed but my html code gets
I have xampp for windows but i don't think the problem is in the xampp but in my code
Code for displaymenus.php:
hello
<?php
require 'controllers/menucontroller.php';
$menuController = new menucontroller();
if(!empty($_POST['types']))
{
$menuTables = $menuController->createmenutables($_POST['types']);
}else{
$menuTables = $menuController->createmenutables('^');
}
$content = $menuController->createtypedropdown() . $menuTables;
$title = 'Deliver4All';
include_once 'template.php';
?>
I have some crawled data in hadoop. I have exported data from hbase table to hive table.. So now I have to access its tables via html, php etc. so that I can display it on web. Is their any tutorial or tool available for it. Please guide me thoroughly. My final aim is to search some record from web from hive table.
you can connect Hive with PHP to show the data in webpage.For that you need to use ThrifSQL.phar.
refer the below code
<html>
<body>
<?php
// Load this lib
require_once __DIR__ . '/ThriftSQL.phar';
// Try out a Hive query
$hive = new \ThriftSQL\Hive( 'localhost', 10000, 'user', 'pass' );
$hql = "SELECT * from default.phpexample";
$client = $hive
->connect()
->setSasl(false)
->queryAndFetchAll($hql);
print_r($client);
echo "<table>
<tr>
<th>site_name</th>
<th>price</th>
</tr>";
foreach ($client as $row) {
echo "<tr>\n";
foreach ($row as $field) {
echo "<td>$field</td>";
}
echo "</tr>\n";
}
echo "</table>\n";
$hive->disconnect();
?>
</body>
</html>
Refer https://github.com/Automattic/php-thrift-sql/blob/master/example.php
I'm trying to include a php file inside another php file, but it is not working and I don't know why.
Moreover, I'm getting no erroes. allow_url_include is enabled in php.ini file.
I'm using XAMPP server.
Below here is part of my code:
q.php
<div class="article">
<? php
include ('a.php');
?>
</div>
where a.php simply has echo statement:
echo "hello";
I'm posting bigger section of my code now.
<div class="artical">
<?php
$username = "root";
$password = "";
$database = "techinsight";
$server = "127.0.0.1";
$db_handle = mysql_connect($server, $username, $password);
$db_found = mysql_select_db($database, $db_handle);
if ($db_found)
{
$SQL = "SELECT * from questions";
$result = mysql_query($SQL);
while($db_field=mysql_fetch_assoc($result))
{
$x = $db_field['Qid'];
while($x==1 && $x==NULL)
{
$SQL = "SELECT * from questions";
$result = mysql_query($SQL);
$db_field = mysql_fetch_assoc($result);
$x = $db_field['Qid'];
}
}
if($x==$x)
{
for($x; $x>0; $x--)
{
$SQL = "SELECT * from questions WHERE Qid=$x";
$result = mysql_query($SQL);
$db_field = mysql_fetch_assoc($result);
$str_que = $db_field['question'];
echo "<div class='dabba'>
<div class='block_a'> <?php include('a.php'); ?> //here it is.
</div> <br>
<div class='block_b'>
it is 2nd section. <br>
</div><br>
<div class='block_c'>
last one.<br> </div>
</div> <br><br>";
}
}
}
?>
</div>
Try:
<?php //Before you had <? php <--
include "a.php";
?>
Make sure the files are in the same directory.
You have a space between <? and php
Remove it.
It can be a couple of things...
1. Place the included file in the correct folder
Make sure that when you use include you either provide the folder path correctly or place the file in the same folder as where you reference / call it from.
2. It is <?php and not <? php
You have a space too much. Actually, if you use <? php I believe PHP will look for a function called php as <? may also be an opening tag (assuming short tags are activated in your php.ini file: short_open_tag=On).
Bonus: make sure error reporting is turned on while debugging
Another thing that I'd recommend you to do is to setup your php.ini file to report for all errors while debugging:
error_reporting(E_ALL);
I haven't tested it, but I'm pretty sure your above code would have resulted in a notification on the missing function php.
And the real bonus (following your updated post) - what you did wrong
You have added the include inside echo - obviously it won't work. So replace this...
echo "<div class='dabba'>
<div class='block_a'> <?php include('a.php'); ?> ...
...with this...
echo "<div class='dabba'>
<div class='block_a'>"; include('a.php'); echo "...