ProgrammingThis forum is for all programming questions.
The question does not have to be directly related to Linux and any language is fair game.
Notices
Welcome to LinuxQuestions.org, a friendly and active Linux Community.
You are currently viewing LQ as a guest. By joining our community you will have the ability to post topics, receive our newsletter, use the advanced search, subscribe to threads and access many other special features. Registration is quick, simple and absolutely free. Join our community today!
Note that registered members see fewer ads, and ContentLink is completely disabled once you log in.
If you have any problems with the registration process or your account login, please contact us. If you need to reset your password, click here.
Having a problem logging in? Please visit this page to clear all LQ-related cookies.
Get a virtual cloud desktop with the Linux distro that you want in less than five minutes with Shells! With over 10 pre-installed distros to choose from, the worry-free installation life is here! Whether you are a digital nomad or just looking for flexibility, Shells can put your Linux machine on the device that you want to use.
Exclusive for LQ members, get up to 45% off per month. Click here for more info.
I'm trying to get a list of tables from chosen sqlite database. If I query the database in a console the query returns the tables properly. If I query the database with the same query in PHP I get no return. I have attached views of what is happening. Code is below: HAPPY NEW YEAR
Code:
<?php
error_reporting (E_ALL ^ E_NOTICE);
include("../myPhpFunctions.inc"); // contains lf(); sp(); myprint; check_input();
// shows break space print_r on browser
$orgdir=getcwd();
$dir="/home/rick/DB-sql/";
$test=$files=array();
// =====================================================
// change to working directory where the databases are and get the *.db files
chdir($dir);
// get the available db file names
if (is_dir($dir)){
if ($dh = opendir($dir)){ // open dir and read contents
while (($file = readdir($dh)) !== false){
if(substr($file, -2)=="db") {
$files[]=$file;
}
}
}
}
closedir($dh);
// =====================================================
?>
<!DOCTYPE HTML>
<html>
<head>
</head>
<body>
<form action="#" method="post">
<p>Databases Available</p>
<!-- <select multiple="multiple" name="database[]"> to pick multiple choices-->
<select name="database" size="5">
<!-- <option value=""></option> first line blank -->
<?php
foreach($files as $file) {
echo "<option value=".$file.">".$file."</option>".lf();
} // foreach
?>
</select>
<p><input type="submit" name="submit" value="Choose Database" /></p>
</form>
<br />
</body>
</html>
<?php
if(isset($_POST['submit'])){
$dbase=$_POST['database'];
// ======================================================================
// Connect to Database and SELECT tables for Dropdown list
// =====================================================================
class MyDB extends SQLite3 {
function __construct() {
$this->open("'".$dbase."'");
//$this->open('/home/rick/Desktop/sqliteDatabases/renoAZID.db');
}
}
$db = new MyDB();
if(!$db) {
echo $db->lastErrorMsg();
} else {
echo "Opened database".sp().$dbase.sp()." successfully".lf();
}
$tablesquery = $db->query("SELECT distinct tbl_name from sqlite_master order by 1;");
$table = $tablesquery->fetchArray();
myprint($table); bye(101); <===== this is print_r with <pre> attached -- bye is exit()
echo '<pre>'.$table['tbl_name'] . '</pre>';
$db->close();
} // isset $_POST
chdir($orgdir);
?>
myprint($table); bye(101); // <===== this is print_r with <pre> attached -- bye is exit()
//echo '<pre>'.$table['tbl_name'] . '</pre>'; <======= this should not have been here
function myprint($array) { <======= I put this in my include file to alias print_r in browser with the <pre> tag echo "<pre>"; print_r($array); "</pre>";
bye(101) <======= same here - alias for exit(Bye from line 101);
}
LinuxQuestions.org is looking for people interested in writing
Editorials, Articles, Reviews, and more. If you'd like to contribute
content, let us know.