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.
Related
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
I wanted to make a simple website, which can open, show, and run sql server queries, just like executing queries from sql server management studio. It already can execute some queries like select (then show it as a table), insert, update, delete, including when i use where/group/order statement.
But, when I doing backup on my database with query :
BACKUP DATABASE 'mydb' TO DISK='pathname\filename.bak' WITH INIT/NOINIT
It can only backup the database once, and then when I execute the query with the same inputs, it got out with no error, but also no file backups produced from the execution. I don't know why, but when i'm executing with the same query from sql server management studio (with different filename so that the previous file didn't get overwritten), it execute without error and creating another file backup.
The code :
php
$sql = "ALTER DATABASE $db_name SET RECOVERY FULL";
$stmt = sqlsrv_query($conn, $sql);
if($stmt === false)
{
die(print_r(sqlsrv_errors()));
}
else
{
echo "Recovery model set to FULL";
}
if($_POST['type']=="Backup Full")
{
$query="BACKUP DATABASE $db_name TO DISK='$file\\$filename.bak' WITH
NOINIT;";
echo "<br>".$query."<br>";
$stat=sqlsrv_query($conn,$query);
if($stat == false)
{
echo "Error to retrieve info, THIS IS THE ERROR : <br />";
die(print_r(sqlsrv_errors()));
}
else
{
echo "Success!";
}
}
It create a new file .bak filled with my database backup
It returns error inside the 'if'
When i tried to run the code again with the different filename, it didn't create anymore .bak file.
When i restarted my PC, things back to normal (creating another .bak again)
It seems there's a solution here. Your issue it happened to me also but in my case sometimes the backup was created and sometimes no and I guess that the backup process fails when php executes and it exits before the ending backup process, therefore, it kills the connection in the middle of backup process. I realized that to execute a sql sequence of no-query type, it has to be consumed with the instruction sqlsrv_next_result till there's no more results.
You should use this snippet in order to execute the backup query successfully.
$query="BACKUP DATABASE $db_name TO DISK='$file\\$filename.bak' WITH NOINIT;";
if ( ($stmt = sqlsrv_query($conn, $query)) )
{
do
{
} while ( sqlsrv_next_result($stmt) ) ;
sqlsrv_free_stmt($stmt);
}else{
die(print_r(sqlsrv_errors()));
}
Using phpmyadmin, i created a mysql stored procedure called mySP(). After creating the SP, i noticed that the SP is located in the information_schema db under ROUTINE table. I can see it here. Now from within phpmyadmin, under my actual database if i use SQL tab and do a call to the procedure using:
CALL mySP();
it works as required. NO issues.
Now i am trying to extend this by having a php page call this SP.
my php code is like this:
<?php
include("include_db_connection.php");
$callSP_query = "CALL mySP()";
$callSP_result = mysqli_query($db_conn, $callSP_query)
or die('Connected to database, but StoredProc failed');
if(!$callSP_result)
{
echo "Error with StoredProc...";
}
else
{
echo "Succsess! Called Stored Proc..";
}
?>
Now on loading this page on the browser, i always get the 'Connected to database, but StoredProc failed' error meaning that connection to db was established successfully, but there is some problem with calling the SP.
what could be the problem? The SP was created successfully and even called successfully from within phpmyadmin. where is the php call going wrong?
thanks!
EDIT:
I just checked the error code using mysqli_error() and it says "PROCEDURE mySP does not exist"
this was an issue with my own code. actually, u dont have to reference or even look into the information_schema. your sp can be called with the above code, if your database connection details are correct :)
This is my first time transferring my local dev site to another local site to test out, and can't access the database in the new site. Both computers are running XAMPP on Macs. The test site has successfully installed XAMPP, and has placed database files under Applications/XAMPP/xamppfiles/var/mysql. The test user is able to start Apache and MySQL, and see database files in PHPMyAdmin. The test user is also able to access the local web site with no error messages.
EDIT: The database files were copied over by copying/zipping the file on my end, and unzipping/dropping the copied files on the test end.
However, the local web site does not seem to see the database. Pages that are supposed to return data just show the default "sorry, we're sold out" message or show "image not found" graphics, and the admin is unable to log in.
The index page calls
include_once "common/base.php";
which consists of
<?php
// Set the error reporting level
error_reporting(E_ALL);
ini_set("display_errors", 1);
// Start a PHP session
session_start();
$_SESSION['docroot'] = $_SERVER['DOCUMENT_ROOT'] . '/mysite/';
// Include site constants
include_once $_SERVER['DOCUMENT_ROOT'] . "/inc/constants.inc.php";
if ( !isset($_SESSION['token']) )
{
$_SESSION['token'] = md5(uniqid(rand(), TRUE));
$_SESSION['token_time'] = time();
}
// Create a database object
try {
$dsn = "mysql:host=".DB_HOST.";dbname=".DB_NAME;
$_db = new PDO($dsn, DB_USER, DB_PASS);
} catch (PDOException $e) {
echo 'Connection failed: ' . $e->getMessage();
exit;
}
?>
If there was a connection problem, I would expect to see an error message returned, which I can verify by changing the constants in inc/constants.inc.php to bogus values. So I don't believe there's a connection problem.
If you were in my position, what would you check?
EDIT: I just found out about the Export function in PHPMyAdmin. I'm going to try deleting the db files that were copied over, exporting the files from PHPMyAdmin, and then importing them in the test machine.
EDIT: I just had the test machine do a simple
$sql = "SELECT FirstName From users";
$stmt = $_db->prepare($sql);
$stmt->execute();
$aaData = array();
while($row = $stmt->fetch(PDO::FETCH_NUM)){
$aaData[] = $row;
}
$stmt->closeCursor();
print_r($aaData);
on the index page, it shows the correct list of users. So the connection is good,
and there's an issue elsewhere. Would y'all say that I still need to delete the copied db and use the "correct" way (export/import), or is that a waste of time?
FINAL EDIT: I did redo the move using Export/Import and everything is working well now. Thanks to all.
First off, zipping files in the mysql data directory and moving them is not the best way to go. It can work if you have completely flushed/shut down the mysql server before moving them. You are better off using mysqldump or a similar tool to move entire databases at a time.
It sounds to me like you moved over your app's database files, but you probably forgot to add the user/password credentials to the new MySQL setup. You mentioned you use phpMyAdmin, so when you login on the other machine click the "Privileges" tab and make sure it matches up with the Privileges tab on your dev machine.
If it's not that, then it is entirely likely that by zipping and copying the files some/all of the tables were corrupted. Try using phpMyAdmin's Export and Import capabilities to move the database over. If the data is very large let me know and I can give you some command line entries to run.
Hope this helps.
I am new to Joomla and new to php (wish I was so new in age too). I have installed joomla on a local apache webserver. I am trying to use some php code in a joomla article in order to fetch some data from a Sybase ASE 12.5 database. I installed sourcerer and started to try an ODBC connection using a system DSN (which I verified it is working):
{source}
<?php
echo 'This text is placed through <b>PHP</b>!';
echo '<p>';
echo '</p>';
$conn = odbc_connect('myDSN', 'sa', 'myPassword') or die('Could not connect !');
echo 'Connected successfully';
$sql = 'SELECT day, name FROM my_table where month = 1';
odbc_close($conn);
?>
{/source}
The above code doesn't do much, but this is how far I can get without problems. I refresh the joomla page and I see inside the article's text:
...
This text is placed through PHP!
Connected successfully
...
Seems ok, the connection obviously established (I verified this by stopping the sybase service and getting the "Could not connect" message). Then I added one more line, just below the $sql assignment.
$rs = odbc_exec($conn,$sql);
I refresh and ...I see nothing coming from the script (not even the "This text is placed through PHP!").
Obviously, I see nothing if I include code to echo the contents of $rs. I also tried this but in vain.
if (!$rs)
{exit("Error in SQL");}
Once I add the odbc_exec command, the entire script ceases working.
In php.ini I read:
; Windows Extensions
; Note that ODBC support is built in, so no dll is needed for it.
Do you have any idea what is going wrong?
UPDATE
Connecting to a MySQL database using code like this, works like a charm.
To answer your question
Is this the correct way to get data
from another database in to an article
or should I use some plug-in to do
that?
The correct way is to use JDatabase object which you get by JFactory::getDBO() or JDatabase::getInstance(), see Joomla JDatabase documentation.
$db = JDatabase::getInstance( $databasConfigArray );
$db->setQuery('your query');
$data = $db->loadObjectList();
Here is a good tutorial showing how to connect to multiple databases in Joomla, there is even source code for helper class.
Also look at this thread Connecting to 3rd party databse in Joomla!?