I am trying to display the results of a SQLite query on browser using php.
I connected to the database using
$conn = new PDO('sqlite:test.db');
Below is my query
$query = $conn->query("SELECT * FROM main");
Below is my fetch function
$row = $query->fetch(PDO::FETCH_ASSOC);
I get the output when I run it from my terminal using
php myscript.php
But when I try to open the same script from browser, its showing empty screen as it is not getting any response from server.
Can anybody help me debugging it ?
Please post if you have any working script for the same. I am out of due to submit my college project.
Related
I use the VirtueMart component on my site.
I have this piece of code running on Joomla 3.6:
<?php
// Get a db connection.
$db = JFactory::getDbo();
// Create a new query object.
$query = $db->getQuery(true);
// Select all records from the user profile table where key begins with
//"custom.".
// Order it by the ordering field.
$query->select($db->quoteName(array('customfield_value',
'virtuemart_product_id')));
$query->from($db->quoteName('jos_virtuemart_product_customfields'));
$query->where($db->quoteName('virtuemart_custom_id') . ' LIKE '. $db-
>quote('3'). ' AND '. $db->quoteName('virtuemart_product_id') . 'LIKE ' .
$db->quote($product->virtuemart_product_id));
// Reset the query using our newly populated query object.
$db->setQuery($query);
// Load the results as a list of stdClass objects (see later for more
options on retrieving data).
$results = $db->loadResult();
echo ($results);
?>
However, for some reason, it's not loading the data. I just get a blank page. On my localhost it's working fine, yet on my live site it's not loading at all.
Any reason why this could be? It's using the same database (phpmyadmin).
Hosting issue possibly?
I don't know. I've tested everything offline for a week and it all went swimmingly and then this happens. I don't see ANY errors in the console, so I don't know what could be wrong.
Thanks for reading.
This problem arises when you transfer your database to the server. because some of the servers have a different configuration for the database server like it may be running a database server on localhost:8080. so first check your DB config file for configuration.if you still found the same problem then I will suggest enabling PHP error reporting to 1 so that you can see what actually causing this problem.
I am a python developer who is completely new to web development. I wish to develop a web service in python which authenticates user and returns a token.
I was able to do that using PHP (thanks to all the blogs available online). But soon realized that I want to do that in python.
Where I am stuck is that-
I don't understand how to fetch the parameters from POST request, like I was fetching in PHP (see code).
How to return a string or code (in PHP it's echo, should I user return?)
// include db connect class
require_once('veggieking_connect.php');
// connecting to db
$db = new VEGGIEKING_CONNECT();
// set mysql_query for utf8
mysql_query ("set character_set_results='utf8'");
$emp_id = $_POST["mEmpID"];
$emp_pwd = $_POST["mPassword"];
$result = mysql_query("select * from empdata where emp_id like '$emp_id' and emp_pwd like '$emp_pwd'") or die(mysql_error());
if(mysql_num_rows($result) > 0) {
while($row = mysql_fetch_assoc($result)) {
echo $row['emp_email'];
}
}
else {
echo "Fail";
}
?>
Just like in PHP, emp_id and emp_pwd are fetched, how to do that in python web serice when I call using the same POST request in android.
I understand it's a simple question, but I can't find any good python web services examples which explains what's happening in the code. If you are aware of where I can learn these, please share the url's also, it would be really helpful.
Thanks.
From your php code i understand bit that you want to retrieve and then fetch data in database. For this purpose in python use "psycopg2" module.
psycopg2 python Documentation
Using this Module you can do any operations related to database from python code.
I hope this will help you.
im trying to write a query to insert data to my remote database table from a CRON file in my remote server. db connection happens through webservice and all that is working fine but the database does not get filled. following is the code that i have written, will anyone of you be able to find why it does not get write to the database table
$link = DbConnection::getInstance('TDC')->connectMysql()
$attributeKey = "12345";
$query_new = "INSERT INTO redtable (message) VALUES ('$attributeKey')";
$result = mysql_query($query_new, $link);
I'm building a Joomla site, but I'm stuck at something, wondering if you guys could kindly help me out.
I'm trying to get an alerting system working.
I essentially need to create a cron job that runs a PHP script every 10 minutes. This PHP script should basically do a select query on the database, and if a particular field has a specific value, then open a website.
So, this is what I have now:
$result = mysql_connect(localhost, myusername, mypassword);
mysql_select_db("database_name");
$result = mysql_query( "SELECT from_table");
The table name is: comments.
The field name is: published.
So what I would ideally need, is that if the value of published = 0, then the php script should open this URL, which will send me an sms message https://www.voipbuster.com/myaccount/sendsms.php?username=xx&password=xx&from=xx&to=xx&text=Alert
And if there is any other value, I don't want it to do anything.
So, anytime there is value 0 I receive a text message.
Hope this makes sense, thanks for your immense patience reading.
Get Andrew Eddie's script for cron plugins and run that. Then write a plugin in the cron group that sends your email.
https://github.com/eddieajau/jc-kodaly
Switch to PDO (or MySQLi). The API you're using is deprecated.
(based on nothing - this is a guess)
$dbh = new PDO('mysql:host=localhost;dbname=test', $user, $pass);
$sql = 'SELECT published FROM sometable';
$stmt = $dbh->prepare($sql);
$stmt->execute();
$stmt->setAttribute(PDO::FETCH_ASSOC);
$row = $stmt->fetch();
if( $row['published'] == 0 )
{
$ch = curl_init(" https://www.voipbuster.com/myaccount/sendsms.php?username=xx&password=xx&from=xx&to=xx&text=Alert");
curl_exec($ch);
curl_close($ch);
}
I have been learning how to program websites lately and the time has come for me to add a database. I have in fact already successfully created a MySQL database and interacted with it with PHP.
My problem is I can't seem to access a SQLite database file with it. I am using MAMP to host locally for now. Here is a snippet of the code I am using to access the db and find and print out a value stored on it.
<?php
$dbhandle = sqlite_open('/Applications/MAMP/db/sqlite/Users');
if ($dbhandle == false) die ('Unable to open database');
$dbquery = "SELECT * FROM usernames WHERE username=trevor";
$dbresult = sqlite_query($dbhandle, $dbquery);
echo sqlite_fetch_single($dbresult);
sqlite_close($dbhandle);
?>
As you have access to the database (your code doesn't die), I'd say there's got to be an error later ;-)
Looking at your SQL query, I see this :
SELECT * FROM usernames WHERE username=trevor
Are you sure you don't need to put quotes arround that string ?
Like this :
SELECT * FROM usernames WHERE username='trevor'
Also, notice that sqlite_fetch_single will only fetch the first row of your data -- which means you might need to use sqlite_fetch_array or sqlite_fetch_object if you want to access all the fields of your resulset.