i would like to ask regarding the php code and oracle sql. I am developing a website for a system as my project task. for the searching page, user can fill in one of the searching field and the system will display all the required details based on what user search for. can anyone teach me on how to do the php code to link with the oracle SQL database. as what i have done so far is:
$sql = "SELECT * FROM sdlrules_tbl_wip_queue
where lotid = trim(upper((:lotid)),
eqpId = trim(upper(:eqpId)),
stepName = trim(:stepName),
sequence = trim(:sequence)";
if($_REQUEST["lotId"]!=""){
$sql .= "SELECT
LOTID,PLAN,STEPSEQ,STEPNAME,LOTTYPE,PRIORITY,DEVICE,EQPID,REMARK
FROM
sdlrules_tbl_wip_queue
WHERE lotid = trim(upper(:lotid))";
}
if($_REQUEST["eqpId"]!=""){
$sql = "SELECT * FROM sdlrules_tbl_wip_queue
WHERE eqpId = ':eqpId'";
}
if($_REQUEST["stepName"]!=""){
$sql = "SELECT * FROM sdlrules_tbl_wip_queue
WHERE stepName = ':stepName'";
}
if($_REQUEST["sequence"]!==""){
$sql = "SELECT * FROM sdlrules_tbl_wip_queue
WHERE sequence = ':sequence'";
}
can anyone teach me on how to do the php code to link with the oracle SQL database.
This is a broad question.
Oracle has two manuals you might want to check out
The Underground PHP and Oracle Manual
Database 2 Day + PHP Developer's Guide
There is some older install content in these books you can skip, but there is much material that is useful.
You simply need to read following resources to connect to Oracle database and perform required operations. Just read functions descriptions. Its pretty straight forward.
http://php.net/manual/en/intro.oci8.php
http://php.net/manual/en/ref.oci8.php
Related
I'm writing here regarding the use of the SQL TBS plugin.
I went through the www.tinybutstrong.com web site, guide, forum, etc., but can't figure out the answer.
I used to use the plugin tbssql_mysql.php, but it became obsolete with PHP7.
I went on the TBS site to get the new version but realised it was now native with TBS, and wasn't a separate module anymore.
But then, I realised I have actually no idea on how to create a new SQL object and perform queries like I used to.
Ie, I used to do this:
include_once('tbssql_mysql.php');
$Db_dev = new clsTbsSQL();
$user = 'root';
$pass = '';
$Db_dev->Connect('localhost:3306',$user,$pass,'ecv');
$query1 = 'SELECT id, page FROM page_menu ORDER BY ordre ASC';
$get_menu = $Db_dev->GetRows($query1);
But I have no idea how to do all of this with this new TBS version.
Could you point me to the documentation regarding connecting to a DB and querying with TBS now?
Kind regards.
Hi I have a strange problem with below sql query.
If I run the query on sql console on phpmyadmin it returns 3 "dimo" vehicle records
SELECT * FROM bdata WHERE vehicle LIKE 'dimo%' // returns 3 records
but if I make a php file and run it does not return any records but if I change the search to car it shows all the records under car.
Please can someone help I tried many things including changing database structure but did not work. I spent almost a week to fix this issue before seeking help on stackoverflow
<?php
define('HOST','****');
define('USER','****');
define('PASS','*****');
define('DB','*******');
$con = mysqli_connect(HOST,USER,PASS,DB);
$sql = "SELECT * FROM bdata WHERE vehicle LIKE 'dimo%' ORDER BY vehicle";
// database has three dimo vehicles but does not show on the php
// but works fine on phpmyadmin console
$res = mysqli_query($con,$sql);
while ($row = mysqli_fetch_array($res))
{
echo $row[15];
}
?>
Please can someone help
I have this problem.. i am trying to use the lock record for the update. I am using php, and i use oracle as the database. i didnt understand fully but i have managed to copy the previous developer code and make it working.
It is using the odbc_exec(), odbc_fetch_row(). I think that this is suppose to be use for microsoft access data base. But i don't know. And i am also using jquery to fetch this php file(using jquery post) and append to the current page.
But now my senior request me to make sure that if a person is editing one record. then the other cant edit it anymore. They said that something about not closing the connection. can php not close connection to database after 1 page is loaded (when it is using jquery to get the page like mine does)? from what i know, if a page is loaded. the connection to the database is closed.
I want to try this code but i am afraid if i am wrong and the connection would hang.
Now my sql is like this for select all company.
$sqlStr ="select * from company";
$rs = odbc_exec($GblConnOra , $sqlStr);
while (odbc_fetch_row($rs)){
$company_name=odbc_result($rs,"company_name");
$company_id=odbc_result($rs,"company_id");
}
And for select the company to edit
$sqlStr ="select * from company where company_id='34'";
$rs = odbc_exec($GblConnOra , $sqlStr);
while (odbc_fetch_row($rs)){
$company_name=odbc_result($rs,"company_name");
}
The updating
$sqlStr ="update compay set company_name=? where company_id=?";
$stmt = odbc_prepare($GblConnOra , $sqlStr);
$res = odbc_execute($stmt, array($company_name, $company_id));
i think the sql will be like this. to lock the record.
$sqlStr ="select * from company for update skip locked";
$rs = odbc_exec($GblConnOra , $sqlStr);
while (odbc_fetch_row($rs)){
$company_name=odbc_result($rs,"company_name");
$company_id=odbc_result($rs,"company_id");
}
can i do this?
what would my sql be for selecting a row to edit?
what would my sql be for updating the row?
And from my understanding, this lock would be release after an update commit or rollback is call.
I am trying to create a "views" system on my books website.
I have the following tables with the following columns:
Books
-bookid
-bookname
-authorid
-views
my webpage is set up to display a book based on the $_GET['bookid'] variable and I want to add 1 (increment the views column by one for that particular book)
I tried using the following code but it didn't update my table:
<?php $sql = "UPDATE `books` \n" . "SET views = views+1 WHERE" . $_GET['bookid'] .= "bookid"; ?>
ALSO: I used dreamweaver to run the recordset query) so maybe something is different.
Please Help!
Sidenote: Can you please recommend a good book/video or written tutorial to learn php and mysql for absolute beginners like my self!
This is important: don't include $_GET paramaters directly in your SQL query.
This makes your website vulnerable to an SQL Injection attack. Sanatise your inputs by using:
$book_id = mysql_real_escape_string($_GET['book_id']); // If it is a string
$book_id = intval($_GET['book_id']); // It it is an integer
// Assuming it is an integer
$sql = "UPDATE books SET views = views+1 WHERE bookid = $book_id";
You obviously need to execute that query, are you doing that?
$user="username";
$password="password";
$database="database";
mysql_connect(localhost,$user,$password);
mysql_select_db($database) or die( "Unable to select database");
mysql_query($sql);
mysql_close();
EDIT:
Also, just a tip, since you're using $_GET you should be executing something like yourscript.php?book_id=12345, is that what you're doing?
you've already found some of the best ways to learn PHP: writing code and coming here when you don't know further :) (don't have a real good tutorial on my hands beyond that ;)
As for your question:
check the value of $_GET['bookid']
check the value of $sql
if all looks as intended, run the query directly
oh wait.
you're not actually executing the sql in your code, just generating a string with the query. you need to open a connection etc, or are you doing that and leaving it out here?
Your query looks slightly off. Try this:
$sql = 'UPDATE books SET views = views+1 WHERE bookid = ' . intval($_GET['book_id']);
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.