php update query always go to else - php

I am trying to update database with php update function but it always goes to else
It seems to me the no syntax error
function UpdateData()
{
$bookid = textboxValue("book_id");
$bookname = textboxValue("book_name");
$bookpublisher = textboxValue("book_publisher");
$bookprice = textboxValue("book_price");
if($bookname&&$bookpublisher&&$bookpublisher){
$sql="UPDATE books SET book_name='$bookname', book_publisher='$bookpublisher', book_price='$bookprice' WHERE id='$bookid' ";
if(mysqli_query($GLOBALS['con'],$sql)){
TextNode("success",'data successfully update');
}else{
TextNode("error","enable to update data");
}
}else{
TextNode("error","select data using edit icon");
}
}
Error:
No data sources are configured to run this SQL

Your error "No data sources are configured to run this SQL" is an IDE specific error for PHPStorm not for your code syntax.
"Live" code errors will be found in your PHP error log.
You can find guidance from JetBrains for setting up your SQL analysis for PHPStorm here.
You may also get help on this topic here: No data sources are configured to run this SQL

Related

Does error handling on every query affects performance?

Hello i'm wondering if putting error handler in every query especially Inserts and Updates affects the performance of web application with huge database? if not how can i use try catch properly on every query to stop the process and inform the user? is it possible to rollback inserted data?
sample error logging:
$query = mysqli_query($conn, "insert into `table`(`fields`) values('$variable')");
if(!$query){
write_mysql_log("logs here", $conn);
echo "<script>alert('Error message, like something went wrong'); window.location = 'page.php';</script>";
}
No. You should be checking for errors from the query.
The check for errors is entirely separate from running the query itself. The query will still return errors, even if you don't check for them.

Oracle different Results between sqldeveloper and PHP

i got a very interessting problem with Oracle and PHP. With PHP i didn't get actual data. I was able to do a update with the form, but still get the old data in the edit page and overview, with different Browser, without Cache on. In SQLdeveloper the data are right .... is there a problem with php and oracle ?
the problem was commit, there seems to be no autocommit with php
there is a php function for this
$r = oci_commit($conn);
if (!$r) {
$e = oci_error($conn);
trigger_error(htmlentities($e['message']), E_USER_ERROR);
}
oci_close($conn);

PHP page loads forever when trying UPDATE to Oracle db

SELECT statements function OK and very fast between my php scripts and Oracle database. But UPDATE satements take forever to run, even a small query updating one row leaves the web browser loading the page for minutes.
This is the sample code that i want to execute from localhost. but the page is loading forever...
The sample code is:
$connect = oci_connect("SYSTEM","admin","XE");
if($connect) {
//echo 'connected';
$qry = oci_parse($connect,"UPDATE USER SET PASSWORD='1234' WHERE USERNAME='abc'");
$res=oci_execute($qry,OCI_COMMIT_ON_SUCCESS);
if($res){
echo "successfully updated";
}
}
else {
echo 'Not connected';
}
Two methods to debug your issue -
Check your query log - If the query is running as you are expecting.
If you are using Mysql this link here can help ->
How can I start and check my MySQL log?
If oracle -> https://docs.oracle.com/cd/E12032_01/doc/epm.921/html_techref/config/querylog/qlovervw.htm
It could be a issue of your development environment.
It also depends on your development environment configured properly.
You can start from your php configuration file(php.ini).
And do edit more details to your question.

Using PHP to connect to MS Access DB using ODBC keeps on locking

I know this is not the best setup, but I'm stuck with it and cannot change it.
PHP connects to a local MS Access DB (.mdb) to log certain activities being done by the script. This works fine when only one instance of the script is running. However, if run two instances, I occasionally get the following error:
odbc_exec(): SQL error: [Microsoft][ODBC Microsoft Access Driver] Could not update; currently locked., SQL state S1000 in SQLExecDirect
This only happens intermittently so I'm assuming it's only when the two scripts both happen to be trying to write to the same table at the same time. I never had this issue with other DBs such as MySQL. How can I tell PHP/ODBC/Access to either not lock or try again if it is locked?
I also usually have the Access DB open on my screen for troubleshooting purposes.
odbc_exec() returns FALSE if the query fails, so you could just check the result of the query and keep trying until it succeeds:
$sql = "UPDATE [Clients] SET [Position]='somewhere' WHERE [ID]=1";
while (TRUE) {
$result = odbc_exec($conn, $sql);
if ($result) {
break;
}
else {
$lastError = odbc_error();
if ($lastError != "S1000") {
echo "ODBC error $lastError";
break;
}
}
sleep(1);
}

php mysql get row

I am trying to use the mysqli to access a mysql database and a table called phptest, with the code below. I am trying to check if row is = 0 or something else but it does not echo anything. What is wrong with the code?
$mysqli = new mysqli("localhost", "root", "", "phptest");
if (!$mysqli) {
echo "Can't connect to MySQL Server. Errorcode: %s\n". mysqli_connect_error();
exit;
}
$query = "SELECT `id` FROM `test` WHERE `email`='example#hotmail.com' AND `password`='5f4dcc3b5aa765d61d8327deb882cf99'";
$query_run = $mysqli->query($query);
$row_cnt = $query_run->num_rows;
if ($row_cnt==0) {
echo 'wrong..';
} else {
echo 'correct!';
}
EDIT: edited the variable in the if statement. I have runned the query directly in the mysql panel in the tabel. I get the right row count then. Why doesnt it work in php ?
Although you are checking for an undefined variable $row_count (which should be $row_cnt, that isn't your immediate problem (you should still fix this). You are getting a fatal error either because:
Your query is failing. Your query may be failing because of a missing field on the table or indeed you are missing the actual table in the database. The query will return FALSE if it fails, but you aren't checking for that, instead you try to access a property of the result. If the query fails, there is no result object, it is a boolean FALSE and will produce a fatal error something like Fatal Error: Trying to access a property of a none object.
You don't have the MySQLi library configured for your PHP installation
To further debug you should turn on error reporting as below, or consult your server's error log.
error_reporting(E_ALL);
ini_set('display_errors', '1');
One thing is that you defined $row_cnt and then checked for $row_count, but that's just a quick look at your program, so there might be something else wrong too.

Categories